IOS 中使用NSMutableAttributString 上添加刪除線,開始使用
NSString *str = [NSString stringWithFormat:@"TAO GE"];
NSMutableAttributedString *mutableStr = [[NSMutableAttributedString alloc]initWithString:str];
[mutableStr addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlineStyleSingle) range:NSMakeRange(4, 2)];
[_tipsLabel setAttributedText:mutableStr];
采用該寫法,IOS 8贞间, 9, 10 都OK粹懒。
但I(xiàn)OS10.3 沒有效果。
后來查閱添加一行代碼顷级,設(shè)置下nsmutableattributeString 基線偏移屬性為0 IOS10.3 能夠正常顯示凫乖。
NSString *str = [NSString stringWithFormat:@"TAO GE"];
NSMutableAttributedString *mutableStr = [[NSMutableAttributedString alloc]initWithString:str];
[mutableStr addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlineStyleSingle) range:NSMakeRange(4, 2)];
[mutableStr addAttribute:NSBaselineOffsetAttributeName value:@(0) range:NSMakeRange(postiontOriginal, str.length - postiontOriginal)];
[_tipsLabel setAttributedText:mutableStr];