Skip to content

Instantly share code, notes, and snippets.

@mdznr
Created May 31, 2014 22:02
Show Gist options
  • Save mdznr/b895c66c231dacdaeed9 to your computer and use it in GitHub Desktop.
Save mdznr/b895c66c231dacdaeed9 to your computer and use it in GitHub Desktop.
An example of how to customize the appearance of `UIBarButtonItem` for @manolosavi
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:[[UIImage imageNamed:@"IMG"] resizableImageWithCapInsets:UIEdgeInsetsMake(4, 4, 4, 4)]
forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setTitleTextAttributes:@{NSFontAttributeName: [UIFont fontWithName:@"Courier" size:16],
NSForegroundColorAttributeName: [UIColor redColor]}
forState:UIControlStateNormal];
@manolosavi
Copy link

Just because it took me a while to translate that into Swift, and it seems like I finally figured it out, here it is:

UIBarButtonItem.appearance().setTitleTextAttributes([UITextAttributeTextColor: self.parentViewController.view.tintColor, UITextAttributeFont: UIFont(name: "Avenir", size: 20)], forState: .Normal)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment