Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zengyun-hacker/6668078 to your computer and use it in GitHub Desktop.
Save zengyun-hacker/6668078 to your computer and use it in GitHub Desktop.
Customize title view of navigation bar
#define FONT(x) [UIFont systemFontOfSize:x]
#define LOADIMAGE(file,ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:ext]]
//set text title
- (void)setNavigationTitle:(NSString *)title{
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.text = title;
titleLabel.font = FONT(13);
titleLabel.textColor = [UIColor whiteColor];
self.navigationItem.titleView = titleLabel;
}
//set image title
- (void)setNavigationTitleWithImage:(NSString *)imageName {
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:LOADIMAGE(imageName, @"png")];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment