Skip to content

Instantly share code, notes, and snippets.

@ferbass
Created October 10, 2013 01:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ferbass/6911840 to your computer and use it in GitHub Desktop.
Save ferbass/6911840 to your computer and use it in GitHub Desktop.
create a dashed border using CoreGraphics, in your custom view puts thats code on drawRect method.
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [[UIColor grayColor] CGColor]);
CGFloat dashes[] = {1,1};
CGContextSetLineDash(context, 0.0, dashes, 2);
CGContextSetLineWidth(context, 1.0);
CGContextMoveToPoint(context, CGRectGetMinX(rect), CGRectGetMaxY(rect));
CGContextAddLineToPoint(context, CGRectGetMaxX(rect), CGRectGetMaxY(rect));
CGContextAddLineToPoint(context, CGRectGetMaxX(rect), CGRectGetMinY(rect));
CGContextAddLineToPoint(context, CGRectGetMinX(rect), CGRectGetMinY(rect));
CGContextAddLineToPoint(context, CGRectGetMinX(rect), CGRectGetMaxY(rect));
CGContextSetShouldAntialias(context, NO);
CGContextStrokePath(context);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment