繁体   English   中英

获取 UILabel 的 NSParagraphStyle

[英]Get NSParagraphStyle of UILabel

有什么方法可以获取UILabelNSParagraphStyle而不是创建新实例并设置每个属性?

您可以使用enumerateAttribute:inRange:options:usingBlock:UILabel对象的attributedText属性上检索NSParagraphStyle

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
}];

该代码未经过测试(可能由于一些小错误而无法编译),但它应该为您提供其背后的想法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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