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

后端 未结 7 1964
长情又很酷
长情又很酷 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: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.

提交回复
热议问题