Created
August 7, 2011 22:48
-
-
Save hamrickdavid/1130891 to your computer and use it in GitHub Desktop.
This file contains 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
typedef void(^DrawView_DrawBlock)(UIView* v,CGContextRef context); | |
@interface DrawView : UIView | |
@property (nonatomic,copy) DrawableView_DrawBlock drawBlock; | |
@end |
This file contains 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
#import "DrawView.h" | |
@implementation DrawView | |
@synthesize drawBlock; | |
- (void)dealloc | |
{ | |
[drawBlock release], drawBlock = nil; | |
[super dealloc]; | |
} | |
- (void)drawRect:(CGRect)rect | |
{ | |
[super drawRect:rect]; | |
CGContextRef context = UIGraphicsGetCurrentContext(); | |
if(self.drawBlock) | |
self.drawBlock(self,context); | |
} | |
@end |
This file contains 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
DrawView* drawableView = [[[DrawView alloc] initWithFrame:CGRectMake(0,0,320,50)] autorelease]; | |
drawableView.drawBlock = ^(UIView* v,CGContextRef context) | |
{ | |
CGPoint startPoint = CGPointMake(0,v.bounds.size.height-1); | |
CGPoint endPoint = CGPointMake(v.bounds.size.width,v.bounds.size.height-1); | |
CGContextSetStrokeColorWithColor(context, [UIColor grayColor].CGColor); | |
CGContextSetLineWidth(context, 1); | |
CGContextMoveToPoint(context, startPoint.x + 0.5, startPoint.y + 0.5); | |
CGContextAddLineToPoint(context, endPoint.x + 0.5, endPoint.y + 0.5); | |
CGContextStrokePath(context); | |
}; | |
[self.view addSubview:drawableView]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment