Yura Chukhlib Yura Chukhlib - 5 months ago 56
iOS Question

Set UINavigationBar with 2 different fonts

I have to set my UINavigationBar with 2 different fonts. I need to have such picture:

enter image description here

It's very easy to create a custom title, but with only 1 font, I've found suck solution:

[self.navigationController.navigationBar setTitleTextAttributes:
@{NSForegroundColorAttributeName:[UIColor redColor],
NSFontAttributeName:[UIFont fontWithName:@"Zapfino" size:21]

But is it possible to co create a title using 2 different fonts?

Answer Source

Use this code -

 UIFont *font1 = [UIFont fontWithName:kMyriadProSemiBold size:15];

NSDictionary *arialDict = [NSDictionary dictionaryWithObject: font1 forKey:NSFontAttributeName];

NSMutableAttributedString *aAttrString1 = [[NSMutableAttributedString alloc] initWithString:@"My" attributes: arialDict];

UIFont *font2 = [UIFont fontWithName:kMyriadProRegular size:15];

NSDictionary *arialDict2 = [NSDictionary dictionaryWithObject: font2 forKey:NSFontAttributeName];

NSMutableAttributedString *aAttrString2 = [[NSMutableAttributedString alloc] initWithString:@"Profile" attributes: arialDict2];

[aAttrString1 appendAttributedString:aAttrString2];
myProfileLabel.attributedText = aAttrString1;

May be you have to change little bit in this code.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download