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

  • 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)
        }
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • WebSocket-Swift Starscream的使用 WebSocket 是 HTML5 一种新的协议。它实...
    香橙柚子阅读 24,192评论 8 184
  • Selina离婚的消息昨天席卷了整个朋友圈,微博头条也尽是关于Selina离婚的消息,说实话,离婚这个消息没什么好...
    dare_to_think阅读 146评论 0 0
  • 亲爱的儿子,在送你的机场,我们父子长谈了两个小时,你一定好奇我都那么忙了,关于美国的种种竟然是那么熟悉,而我是压根...
    陈广才阅读 269评论 2 2
  • 伴随《蒹葭》的吟诵,开启了我们中国诗词大会的大门。 先来看几道题,你会多少?
    老羊村长阅读 427评论 0 1