简体   繁体   中英

Get NSParagraphStyle of UILabel

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM