有没有办法获得UILabel的NSParagraphStyle,而不是创建新的实例并设置每个属性?
发布于 2017-04-27 20:11:10
可以使用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
}];代码没有经过测试(可能会因为一些小错误而无法编译),但它应该会让您了解它背后的想法。
https://stackoverflow.com/questions/43637357
复制相似问题