美文网首页
swift3--UILabel富文本添加删除线

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

作者: UnsanYL | 来源:发表于2017-05-11 10:52 被阅读0次

先上效果图:

效果图
最近在做的东西涉及到给文字添加删除线,参考以前富文本添加下划线的做法改了变量名之后一直还是没有出来,发现需要添加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

相关文章

网友评论

      本文标题:swift3--UILabel富文本添加删除线

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