0

I am working on changing the font size of attributed and non attributed label texts. I want to scan all the UIlabel in my UIView then based on whether they are attributed text holder I want to increase the font size of entire label while preserving the current font attributes like bold, italic, color etc.

if ([vv isKindOfClass:[UILabel class]])
     {
       UILabel *lbl = (UILabel *)vv;
       NSDictionary *attributes = [(NSAttributedString *)lbl.attributedText 
       attributesAtIndex:0 effectiveRange:NULL];
       if(attributes)
       {
        lbl.attributedText = [[NSAttributedString alloc] initWithString:lbl.text
        attributes:attributes];
        lbl.font=[UIFont fontWithDescriptor:[UIFontDescriptor
        fontDescriptorWithFontAttributes:attributes] 
        size:lbl.font.pointSize+self.fontsize];
       }
    }

Using the below line of code I end up skipping the text attributes and it picks the very first font name and apply to the rest of string in label's text

lbl.font=[UIFont fontWithName:[lbl.font fontName] size:lbl.font.pointSize+self.fontsize];

I want to increase font size yet maintain the font attributes Any help will be appreciated Thanks

Larme
  • 24,190
  • 6
  • 51
  • 81
Vikas Ojha
  • 444
  • 1
  • 8
  • 23
  • possible duplicate of [Looping Through NSAttributedString Attributes to Increase Font SIze](http://stackoverflow.com/questions/19386849/looping-through-nsattributedstring-attributes-to-increase-font-size) – Cyrille Sep 09 '14 at 10:25
  • 1
    Create a mutable copy of the attributes dictionary and get the `NSFontAttributeName` "font value" out of that and if that's non-`nil`, create a new font from the "font value" with increased size. Then replace the `NSFontAttributeName` entry and re-apply the attributes to the attributed string. – trojanfoe Sep 09 '14 at 10:26

0 Answers0