Create a dashed border using CoreGraphics on iOS
In your custom view subclass 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);
}
Written by Fernando Ribeiro
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Uiview
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#