Created
March 21, 2013 14:25
-
-
Save mundstein/5213413 to your computer and use it in GitHub Desktop.
UIView for deleting icons: little x in a circle added to the top left.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CancelView.m | |
// | |
// Created by Sascha Mundstein on 3/21/13. | |
// Copyright (c) 2013 Erica Sadun. All rights reserved. | |
// | |
@interface CancelView : UIView | |
@end | |
@implementation CancelView | |
- (id)initWithFrame:(CGRect)frame | |
{ | |
self = [super initWithFrame:frame]; | |
if (self) { | |
self.backgroundColor = [UIColor clearColor]; | |
} | |
return self; | |
} | |
- (void)drawRect:(CGRect)rect | |
{ | |
CGFloat l = 6.0; // line width | |
CGFloat offset = 0.2; // proportion of view to be used | |
CGColorRef lineColor = [UIColor whiteColor].CGColor; | |
CGColorRef fillColor = [UIColor blackColor].CGColor; | |
//[UIColor colorWithRed:128/255.0 green:0 blue:0 alpha:1.0].CGColor; | |
CGRect circleFrame = CGRectMake(l, l, rect.size.width-2*l, rect.size.height-2*l); | |
CGContextRef context = UIGraphicsGetCurrentContext(); | |
CGContextSetLineWidth(context, l); | |
CGContextSetStrokeColorWithColor(context, lineColor); | |
CGContextSetFillColorWithColor(context, fillColor); | |
// outer circle | |
CGContextAddEllipseInRect(context, circleFrame); | |
CGContextStrokePath(context); | |
// black background | |
CGContextAddEllipseInRect(context, circleFrame); | |
CGContextFillPath(context); | |
// X in the center | |
CGRect xFrame = circleFrame; | |
CGContextSetLineWidth(context, l/2.0); | |
xFrame.origin.x += circleFrame.size.width * offset; | |
xFrame.origin.y += circleFrame.size.height * offset; | |
xFrame.size.width = circleFrame.size.width * (1-offset*2); | |
xFrame.size.height = circleFrame.size.width * (1-offset*2); | |
CGContextMoveToPoint(context, xFrame.origin.x, xFrame.origin.y); | |
CGContextAddLineToPoint(context, CGRectGetMaxX(xFrame), CGRectGetMaxY(xFrame)); | |
CGContextMoveToPoint(context, CGRectGetMaxX(xFrame), xFrame.origin.y); | |
CGContextAddLineToPoint(context, xFrame.origin.x, CGRectGetMaxY(xFrame)); | |
CGContextStrokePath(context); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment