0

I am using this link here to change the font and color of title in navigation bar. I also tried this. Both of them run fine in ios8 but when i test in ios7 each time it crashes at "NSFontAttributeName". If i remove the code to set the font and only set the color , it works.

The crash message that I get is * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[1]

Any help would be appreciated. Hope my problem is clear.

Community
  • 1
  • 1
Alejandro Vargas
  • 1,327
  • 12
  • 26
  • 2
    Are you sure the custom font file is available in the bundle? It crashing because of a `nil` value for your font – Anil Varghese Nov 27 '14 at 09:50
  • 2
    the crash happens probably because your font has not been loaded and you try to insert a `nil` value directly. have you checked your font is loaded properly? is the font-name correct? – holex Nov 27 '14 at 10:34
  • That was the issue ! damn silly of me @anil – Alejandro Vargas Nov 30 '14 at 10:01

2 Answers2

-1

Use this code:

UINavigationBar *navBar = [UINavigationBar appearance];
[navBar setTitleTextAttributes:@{NSFontAttributeName: [UIFont fontWithName:@"yourFont" size:15]];
Eilon
  • 2,698
  • 3
  • 16
  • 32
-1

Try this, it works fine for me in both IOS8 as well as IOS7 `

NSShadow * shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor clearColor];
shadow.shadowOffset = CGSizeMake(0, 0);
[self.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:@"custom-color",
                                                 NSShadowAttributeName: shadow,
                                                 NSFontAttributeName: @"font-name",
                                                 }];`
Suhaiyl
  • 1,071
  • 9
  • 17