0

i want to change the appearance of the nav bar, and so far i was able to change the background image of the nav bars, and also with the color.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:     (NSDictionary *)launchOptions {

//set the bg image of all nav bars
UIImage *navBackgroundImage = [UIImage imageNamed:@"navigationBackground.png"];
[[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];

return YES;

//customizing the title text of the nav bars
[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
                                                       [UIColor colorWithRed:255.0/255.0 green:250.0/250.0 blue:240.0/240.0 alpha:1.0], UITextAttributeTextColor,
                                                       [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8],UITextAttributeTextShadowColor,
                                                       [NSValue valueWithUIOffset:UIOffsetMake(0, 1)],
                                                       UITextAttributeTextShadowOffset,
                                                       [UIFont fontWithName:@"Heiti TC" size:21.0], UITextAttributeFont, nil]];

}

this is the code i used to achieve changing the nav bar bg image and the color. if you look into the 2nd UINavigationBar appearance statement, i try to set the font of the nav bar with
[UIFont fontWithName:@"Heiti TC" size:21.0]

but it wont change the font. btw i run this with iphone 6.1 simulator on xcode 4.6.2. im am sure that the font name is "Heiti TC".

Bradley W
  • 3
  • 5

3 Answers3

1

Maybe it doesn't work because you

return YES;

before changing the font?

Michał Ciuba
  • 7,876
  • 2
  • 33
  • 59
  • wow , how did i not see that! you sir are correct, i dont know why i had my return before it but after changing my nav background image. Thank you!! – Bradley W Jun 07 '13 at 09:07
0

Everything looks right. I have used similar code to achieve it as expected. Have you tried using the font Heiti TC Light or Heiti TC Medium?

Adithya
  • 4,545
  • 3
  • 25
  • 28
0

The name supplied for the method fontWithName is not the same as the displayed family name of the font.

Try "STHeitiTC-Light" or "STHeitiTC-Medium" instead.

[UIFont fontWithName:@"STHeitiTC-Medium" size:21.0]

And put the

return YES

at the end of the didFinishLaunchingWithOptions.

PS: The answer here is quite helpful to find the font name to be used: Cant find custom font - iOS

Community
  • 1
  • 1
Valent Richie
  • 5,226
  • 1
  • 20
  • 21
  • tried both and still wont change the font. i also change my code to the one that @kap Suggested, which was the code that ray wenderlich wrote btw. – Bradley W Jun 07 '13 at 09:03
  • yes thank you! i had myn before it for some reason and it was after i changed the nav bg image. thank you verbumdei! – Bradley W Jun 07 '13 at 09:08