美文网首页
iOS SDK 系统 Bug 汇总及解决方案

iOS SDK 系统 Bug 汇总及解决方案

作者: BlessNeo | 来源:发表于2017-04-06 17:24 被阅读74次
  • iOS 10.3

  • 使用NSStrikethroughStyleAttributeName添加删除线失效

添加删除线经常用在商品原价情形下,使用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. Overriding drawText:in:can be slow especially on Collection View or Table View Cells.

方案2:(不推荐)

I make custom UILabel class and override drawText
function, it works for NSStrikethroughStyleAttributeName
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)
        }
    }
}

相关文章

网友评论

      本文标题:iOS SDK 系统 Bug 汇总及解决方案

      本文链接:https://www.haomeiwen.com/subject/kmpqattx.html