Skip to content

Instantly share code, notes, and snippets.

@vtourraine
Created September 4, 2013 10:04
Show Gist options
  • Save vtourraine/6435087 to your computer and use it in GitHub Desktop.
Save vtourraine/6435087 to your computer and use it in GitHub Desktop.
+ (void)customizeAppearance
{
UIColor *lightColor = [UIColor lightGrayColor];
UIColor *darkColor = [UIColor darkGrayColor];
// Navigation bar
UIGraphicsBeginImageContext(CGSizeMake(1, 1));
UIBezierPath *rectBezierPath = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 1, 1)];
[lightColor setFill];
[rectBezierPath fill];
[[UINavigationBar appearance] setBackgroundImage:UIGraphicsGetImageFromCurrentImageContext() forBarMetrics:UIBarMetricsDefault];
UIGraphicsEndImageContext();
[[UINavigationBar appearance] setTitleTextAttributes:@{
UITextAttributeTextColor : [UIColor whiteColor],
UITextAttributeTextShadowColor : [UIColor clearColor],
UITextAttributeFont : [UIFont fontWithName:@"HelveticaNeue-Bold" size:20] }];
// Bar button item
CGFloat corner = 10;
CGFloat cornerRadius = corner/2;
UIGraphicsBeginImageContext(CGSizeMake(corner, corner));
UIBezierPath *roundedBezierPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, corner, corner) cornerRadius:cornerRadius];
[darkColor setFill];
[roundedBezierPath fill];
[[UIBarButtonItem appearance] setBackgroundImage:[UIGraphicsGetImageFromCurrentImageContext() resizableImageWithCapInsets:UIEdgeInsetsMake(cornerRadius, cornerRadius, cornerRadius, cornerRadius)
resizingMode:UIImageResizingModeStretch]
forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
UIGraphicsEndImageContext();
[[UIBarButtonItem appearance] setTitleTextAttributes:@{ UITextAttributeTextColor : [UIColor whiteColor], UITextAttributeTextShadowColor : [UIColor clearColor] }
forState:UIControlStateNormal];
[[UIBarButtonItem appearance] setTitleTextAttributes:@{ UITextAttributeTextColor : [UIColor grayColor] }
forState:UIControlStateDisabled];
[[UIBarButtonItem appearance] setTitleTextAttributes:@{ UITextAttributeTextColor : [UIColor whiteColor] }
forState:UIControlStateHighlighted];
// Back bar button item
CGSize backButtonSize = CGSizeMake(20, 32);
CGFloat headWidth = 12;
UIGraphicsBeginImageContextWithOptions(backButtonSize, NO, [UIScreen mainScreen].scale);
UIBezierPath *backButtonPath = [UIBezierPath bezierPath];
[backButtonPath moveToPoint:CGPointMake(1, backButtonSize.height/2)];
[backButtonPath addLineToPoint:CGPointMake(headWidth, 1)];
[backButtonPath addArcWithCenter:CGPointMake(backButtonSize.width-1-cornerRadius, 1+cornerRadius) radius:cornerRadius startAngle:-M_PI_2 endAngle:0 clockwise:YES];
[backButtonPath addArcWithCenter:CGPointMake(backButtonSize.width-1-cornerRadius, backButtonSize.height-2-cornerRadius) radius:cornerRadius startAngle:0 endAngle:M_PI_2 clockwise:YES];
[backButtonPath addLineToPoint:CGPointMake(headWidth, backButtonSize.height-2)];
[backButtonPath closePath];
[darkColor setFill];
[backButtonPath fill];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:[UIGraphicsGetImageFromCurrentImageContext() stretchableImageWithLeftCapWidth:headWidth+1 topCapHeight:backButtonSize.height/2]
forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
UIGraphicsEndImageContext();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment