我试图以以下方式设置一个NSMutableParagraphStyle:
@IBOutlet weak var headline: UILabel! {
didSet {
let style = NSMutableParagraphStyle()
style.maximumLineHeight = 15
style.lineSpacing = 0
style.alignment = .center
let attributes: [NSAttributedStringKey : Any] = [NSAttributedStringKey.paragraphStyle : style,
NSAttributedStringKey.baselineOffset : 0]
let attributedString = NSMutableAttributedString(string: headline.text!, attributes: attributes)
headline.attributedText = attributedString
}
}...which 没有改变文本在iOS 10.3.2和.3上的外观。它在iOS 9和iOS 11上工作。
我添加了baselineOffset,它似乎解决了一些用户(雷达)的问题--这对我的情况没有帮助。还有其他的解决办法吗?还是所有10.3.x的用户现在都不得不整天忍受着布局的破坏?
编辑:@Larme --我试过这样做,但也不起作用:
let attributedString = NSMutableAttributedString(string: headline.text!, attributes: attributes)
attributedString.addAttribute(NSAttributedStringKey.backgroundColor, value: UIColor.blue, range: NSMakeRange(0, 3))
headline.attributedText = attributedString编辑:在iOS 10.3和11设备上测试matt的代码后,我得出结论,设置行距和设置最大高度的文本对齐不受限制是有问题的。即使没有在代码中执行任何操作,只使用Xcode UI设置属性化文本,我也会得到以下结果(请注意行距):


iOS 11设备

iOS 10.3.3设备

发布于 2018-04-25 09:12:56
不是的。这绝对是一个缺陷,我认为没有任何可能的方式来解决,除非让苹果修补它。
对不起:(
https://stackoverflow.com/questions/49735263
复制相似问题