Yuri Chukhlib
Yuri Chukhlib

Reputation: 120

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?

Upvotes: 0

Views: 72

Answers (1)

Avinash651
Avinash651

Reputation: 1399

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.

Upvotes: 3

Related Questions