What is the best way to implement a UINavigationBar that has a custom background and a custom title font, for both iOS4 and iOS5?
Asked
Active
Viewed 1,498 times
3 Answers
3
for background, just see here UINavigationBar (CustomBackground)
and for font you can use a text label to set font in iOS4 and in iOS5 you can do it like this
self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:12.0f] forKey:UITextAttributeFont];

Community
- 1
- 1

cloudycliff
- 299
- 1
- 8
3
In iOS 5.x, you can use UINavigationBar's setTitleTextAttributes for setting the font, color, offset, and shadow color of the title.
In iOS 4.x, it is not a bad idea to set a UILabel as the titleView property of the navigationBar.

CodaFi
- 43,043
- 8
- 107
- 153
0
Override drawRect
in a custom UINavigationBar
class:
- (void)drawRect {
[super drawRect];
[self addSubview:customNavigationBackgroundView];
}
Then, in the class that uses this navigation bar, run navigationBar.titleView = desiredTitleLabel
. To customize the font of this label, try desiredTitleLabel.font = [UIFont fontWithName:@"name" size:22.0]
.
You can then customize the text color, shadow, etc. of the shadow.

aopsfan
- 2,451
- 19
- 30