Skip to content

Instantly share code, notes, and snippets.

@hirad
Created October 17, 2014 18:03
Show Gist options
  • Save hirad/935ebec56a85707d8667 to your computer and use it in GitHub Desktop.
Save hirad/935ebec56a85707d8667 to your computer and use it in GitHub Desktop.
Simple example of custom drawing
@implementation LHLPrettyView
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
CGSize totalSize = self.bounds.size;
CGFloat fraction = 0.8;
CGFloat radius = rintf(MIN(totalSize.height * fraction / 2, totalSize.width * fraction / 2)); // Why did we use rintf?
[[UIColor redColor] setFill]; // Note: single fill color
CGFloat offset = 100.0;
CGPoint center = self.center;
CGPoint arc1Center = CGPointMake(center.x, center.y-offset);
CGPoint arc2Center = CGPointMake(center.x, center.y+offset);
UIBezierPath* path = [UIBezierPath bezierPathWithArcCenter:arc1Center
radius:radius
startAngle:0.0
endAngle:M_PI
clockwise:NO];
[path addArcWithCenter:arc2Center
radius:radius
startAngle:M_PI
endAngle:2*M_PI
clockwise:NO];
[path closePath]; // tell the path to draw in current context
[path fill]; // apply current fill to path
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment