NSStrikethroughStyleAttributeName , How to strike out the string in iOS 10.3?

后端 未结 7 2022
长情又很酷
长情又很酷 2020-12-07 01:38

I have used this line of code before release of iOS 10.3 ,and worked fine.

NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] in         


        
7条回答
  •  旧时难觅i
    2020-12-07 02:42

    ***You can pass it to function & Enjoy !!!

    func customString(currentprice:String,oldPrice:String) -> NSMutableAttributedString{
            // 1
            let NewString = currentprice + "  " + oldPrice
    
            let string = NewString as NSString
            let attributedString = NSMutableAttributedString(string: string as String)
    
            // 2
            let firstAttributes = [NSForegroundColorAttributeName: UIColor(red: 238/255, green: 140/255, blue: 84/255, alpha: 1),NSBaselineOffsetAttributeName:1]
            let secondAttributes = [NSForegroundColorAttributeName: UIColor.lightGrayColor(), NSStrikethroughStyleAttributeName: 1]
    
            // 3
            attributedString.addAttributes(firstAttributes, range: string.rangeOfString(currentprice))
            attributedString.addAttributes(secondAttributes, range: string.rangeOfString(oldPrice))
    
            return attributedString
        }
    

    and use like:

    YourUILabel.attributedText   = customString("300", oldPrice: "400")
    

提交回复
热议问题