-
iOS 10.3
-
使用
NSStrikethroughStyleAttributeName
添加刪除線失效
添加刪除線經(jīng)常用在商品原價情形下技潘,使用NSStrikethroughStyleAttributeName
添加刪除線在 iOS10.3之前沒什么問題笼平,結果出來一個奇葩的版本10.3(10.3.1依然未解決這個 bug),刪除線渲染不出來豆巨。
目前已知的有效解決方案如下:
方案1:(推薦)
Adding a
NSBaselineOffsetAttributeName
, as explained here, to the attributed string brings back the strikethrough line. OverridingdrawText:in:
can be slow especially on Collection View or Table View Cells.
方案2:(不推薦)
I make custom UILabel class and override drawText
function, it works forNSStrikethroughStyleAttributeName
attribute. But its not support multiple line texts in simple string
.
/// This UILabel subclass accomodates conditional fix for NSAttributedString rendering broken by Apple in iOS 10.3
final class PriceLabel: UILabel {
override func drawText(in rect: CGRect) {
guard let attributedText = attributedText else {
super.drawText(in: rect)
return
}
if #available(iOS 10.3, *) {
attributedText.draw(in: rect)
} else {
super.drawText(in: rect)
}
}
}