Skip to content

Instantly share code, notes, and snippets.

@dylanbeadle
Last active August 29, 2015 14:00
Show Gist options
  • Save dylanbeadle/11357469 to your computer and use it in GitHub Desktop.
Save dylanbeadle/11357469 to your computer and use it in GitHub Desktop.
Custom Back Button
- (UIView *)backButton
{
// Button
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
backButton.frame = CGRectMake(0.0, 0.0, 50.0, 50.0);
[backButton addTarget:self.navigationController action:@selector(popViewControllerAnimated:) forControlEvents:UIControlEventTouchUpInside];
// Custom back arrow
UIBezierPath *backArrowPath = [UIBezierPath bezierPath];
[backArrowPath moveToPoint: CGPointMake(15, 25)];
[backArrowPath addLineToPoint: CGPointMake(20, 31)];
[backArrowPath addLineToPoint: CGPointMake(15, 35)];
[backArrowPath addLineToPoint: CGPointMake(5, 25)];
[backArrowPath addLineToPoint: CGPointMake(15, 15)];
[backArrowPath addLineToPoint: CGPointMake(20, 20)];
[backArrowPath addLineToPoint: CGPointMake(15, 25)];
[backArrowPath closePath];
CAShapeLayer *backArrowShapeLayer = [CAShapeLayer layer];
backArrowShapeLayer.path = [backArrowPath CGPath];
backArrowShapeLayer.strokeColor = [[UIColor grayColor] CGColor];
backArrowShapeLayer.lineWidth = 1.0;
backArrowShapeLayer.fillColor = nil;
[backButton.layer addSublayer:backArrowShapeLayer];
// TODO: Subclass button to set highlight state
// http://robots.thoughtbot.com/post/33427366406/designing-for-ios-taming-uibutton
return backButton;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment