Skip to content

Instantly share code, notes, and snippets.

@jrturton
Last active December 21, 2015 20:58
Show Gist options
  • Save jrturton/6364558 to your computer and use it in GitHub Desktop.
Save jrturton/6364558 to your computer and use it in GitHub Desktop.
Navigation back buttons themed like iOS7, for iOS 5 and 6
-(void)themeBackButtons
{
// Appearance proxy methods
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:[UIImage backButtonImage] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(7.0, 0.0) forBarMetrics:UIBarMetricsDefault];
}
// The image above is generated by this method
+(UIImage *)backButtonImage
{
UIGraphicsBeginImageContextWithOptions(CGSizeMake(30.0,22.0), NO, 0.0);
UIBezierPath *arrowPath = [UIBezierPath bezierPath];
CGFloat edge = 13.0;
CGFloat lineWidth = 3.0;
[arrowPath moveToPoint:CGPointMake(0.0, edge)];
[arrowPath addLineToPoint:CGPointMake(0.0, 0.0)];
[arrowPath addLineToPoint:CGPointMake(edge, 0.0)];
arrowPath.lineWidth = lineWidth;
[arrowPath applyTransform:CGAffineTransformMakeRotation(-M_PI_4)];
CGRect pathFrame = [arrowPath bounds];
[arrowPath applyTransform:CGAffineTransformMakeTranslation(lineWidth, pathFrame.size.height * 0.5 + lineWidth * 0.5)];
// Put your app's theme colour here
[[UIColor redColor] set];
[arrowPath stroke];
UIImage *returnImage = [UIGraphicsGetImageFromCurrentImageContext() resizableImageWithCapInsets:UIEdgeInsetsMake(0.0, edge, 0.0, 1.0)];
UIGraphicsEndImageContext();
return returnImage;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment