Get NSParagraphStyle of UILabel

555 Views Asked by At

Is there any way to get the NSParagraphStyle of an UILabel instead of creating a new instance and settings every attribute?

1

There are 1 best solutions below

3
Larme On

You can use enumerateAttribute:inRange:options:usingBlock: to retrieve the NSParagraphStyle on the attributedText property of your UILabel object:

NSAttributedString *attributedString = myLabel.attributedText;

[attributedString enumerateAttribute:NSParagraphStyleAttributeName
                             inRange:NSMakeRange(0, attributedString.length)
                             options:0
                          usingBlock:^(id value, NSRange range, BOOL *stop) {

                       NSParagraphStyle *paragraphStyle = value; // Do what you want with paragraph
}];

The code is not tested (may not compile due to some small mistakes), but it should give you the idea behind it.