label添加删除线

版权声明: https://blog.csdn.net/baidu_33440774/article/details/81280647

label = UILabel.init(frame: CGRect.init(x: 20, y: 200, width: 500, height: 40))

        label.font = UIFont.systemFont(ofSize: 14)

        view.addSubview(label)

let attributedStr = NSMutableAttributedString.init(string: "一条删除线,两条删除线,加粗删除线")

        attributedStr.addAttributes([NSAttributedStringKey.strikethroughStyle : NSUnderlineStyle.styleSingle.rawValue], range: NSRange.init(location: 0, length: 5))

        attributedStr.addAttributes([NSAttributedStringKey.strikethroughStyle : NSUnderlineStyle.styleDouble.rawValue], range: NSRange.init(location: 6, length: 5))

        attributedStr.addAttributes([NSAttributedStringKey.strikethroughStyle : NSUnderlineStyle.styleThick.rawValue], range: NSRange.init(location: 12, length: 5))

        label.attributedText = attributedStr

猜你喜欢

转载自blog.csdn.net/baidu_33440774/article/details/81280647