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

后端 未结 7 1855
长情又很酷
长情又很酷 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条回答
  • 2020-12-07 02:17

    it is the bug in iOS 10.3 , NSStrikethroughStyleAttributeName (any NSUnderlineStyle cases) is not working any more on iOS SDK 10.3.

    if anyone found the updated answer related to this , please inform here, I will update my answer.

    Product Version: 10.3

    Created: 14-Mar-2017

    Originated: 14-Mar-2017

    Open Radar Link: http://www.openradar.appspot.com/31034683

    Radar status is Currently Open state

    you can see the alternate sample also here may be it useful.

    0 讨论(0)
  • 2020-12-07 02:22

    Just Use this :-

    NSMutableAttributedString *costPrice = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"₹ %@",strDetails]]; [costPrice addAttribute:NSBaselineOffsetAttributeName value:[NSNumber numberWithInteger: NSUnderlineStyleSingle] range:NSMakeRange(0,costPrice.length)];

    This is temp solution . Hope it works

    0 讨论(0)
  • 2020-12-07 02:29

    iOS 10.3 onward you need to add NSBaselineOffsetAttributeName.

    NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n%@",strMRP,strOffer]];
    [attributeString addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:12] range:NSMakeRange(0, strMRP.length)];
    [attributeString addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:15] range:NSMakeRange(strMRP.length, strOffer.length+1)];
    [attributeString addAttribute:NSBaselineOffsetAttributeName
                        value:[NSNumber numberWithInteger: NSUnderlineStyleNone]
                        range:NSMakeRange(0,strMRP.length)];
    [attributeString addAttribute:NSStrikethroughStyleAttributeName
                        value:[NSNumber numberWithInteger: NSUnderlineStyleDouble]
                        range:NSMakeRange(0,strMRP.length)];
    

    Once you add NSBaselineOffsetAttributeName then it works for single line, double line ect.

    0 讨论(0)
  • 2020-12-07 02:33

    It work fine with

       NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n%@",strMRP,strOffer]];
    
    [attributeString addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:12] range:NSMakeRange(0, strMRP.length)];
    
    [attributeString addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:15] range:NSMakeRange(strMRP.length, strOffer.length+1)];
    
    [attributeString addAttribute:NSBaselineOffsetAttributeName
                            value:[NSNumber numberWithInteger: NSUnderlineStyleNone]
                            range:NSMakeRange(0,strMRP.length)];
    [attributeString addAttribute:NSStrikethroughStyleAttributeName
                            value:[NSNumber numberWithInteger: NSUnderlineStyleDouble]
                            range:NSMakeRange(0,strMRP.length)];
    
    0 讨论(0)
  • 2020-12-07 02:40

    As mentioned above, this is an iOS 10.3 bug.

    We needed an immediate workaround, so just in case anyone is looking for hints: Our Label had attributes set through both NSMutableAttributedString as well as NSMutableParagraphStyle. The bug did not occur when using no / an "empty" paragraph style (instance without any properties set).

    So in this scenario, omitting the paragraph style and working around the then missing paragraph properties resolved the issue for us.

    0 讨论(0)
  • 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")
    
    0 讨论(0)
提交回复
热议问题