swift3--UILabel富文本添加删除线

先上效果图:

效果图

最近在做的东西涉及到给文字添加删除线,参考以前富文本添加下划线的做法改了变量名之后一直还是没有出来,发现需要添加NSBaselineOffsetAttributeName。如下

            let previousPrice = "$" + String(product.unitPrice / product.discount)
            let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: previousPrice, attributes: [NSFontAttributeName:UIFont(name: "HelveticaNeue-Light", size: 11.0)!])
            attributeString.addAttribute(NSBaselineOffsetAttributeName, value: 0, range: NSMakeRange(0, attributeString.length))
            attributeString.addAttribute(NSStrikethroughStyleAttributeName, value: 1, range: NSMakeRange(0, attributeString.length))
            attributeString.addAttribute(NSForegroundColorAttributeName, value: UIColor.lightGray, range: NSRange(location:0,length:attributeString.length))

            let currentPrice : NSMutableAttributedString = NSMutableAttributedString(string: productPrice + "    ")
            currentPrice.append(attributeString)
            cell.productPriceLabel.attributedText = currentPrice

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

推荐阅读更多精彩内容

  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 47,053评论 6 342
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,347评论 19 139
  • 风萧萧兮易水寒, 壮士一去兮不复还, 归去来兮…… 站在历史的今天, 俯视来时的昨天, 正如呱呱坠地的小人, 迷茫...
    王文英wwy阅读 4,755评论 0 0
  • 愿,来生,不见不欠不思念, 便能各自安好再无抱怨。 这一生,深情眷恋; 这一生,无缘短暂。 ​​​
    胖乎乎先生阅读 838评论 0 10