0

I am trying to change font size, but there something wrong with my code? I can able to set font size of text1 to text3 but text4 isn't able to work and doesn't change font size to 16. text1 text2 text3 text4

NSString *String1 = [NSString stringWithFormat:@"%@\%@\n%@\%@",text1,text2,text3,text4];
NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:String1];
NSDictionary <NSAttributedStringKey, id> *attributes0 = @{NSFontAttributeName: [UIFont fontWithName:fonts size:10]};
[attributedText addAttributes:attributes0 range:[String1 rangeOfString:text1]];
NSDictionary <NSAttributedStringKey, id> *attributes2 = @{NSFontAttributeName:[UIFont fontWithName:fonts size:12]};        
[attributedText addAttributes:attributes2 range:[String1 rangeOfString:text2]];
NSDictionary <NSAttributedStringKey, id> *attributes4 = @{NSFontAttributeName:[UIFont fontWithName:fonts size:14]};
[attributedText addAttributes:attributes4 range:[String1 rangeOfString:text3]];
NSDictionary <NSAttributedStringKey, id> *attributes4 = @{NSFontAttributeName:[UIFont fontWithName:fonts size:16]};
[attributedText addAttributes:attributes4 range:[String1 rangeOfString:text4]];

text1 text2 text3 text4(font size is not working and just shows the default size of main string of * . size to 13 only)

Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

0

Have you try changing your variable name, it might cause confusion.

In your third attribute change attributes4 to attribute3

NSDictionary <NSAttributedStringKey, id> *attributes3 = @{NSFontAttributeName:[UIFont fontWithName:fonts size:14]};
        [attributedText addAttributes:attributes3 range:[String1 rangeOfString:text3]];
Pepeng Hapon
  • 357
  • 1
  • 17