如果設(shè)置lable一部分有下滑劃線荔睹、斜線時(shí)一部分沒(méi)有時(shí),需要注意iOS10.3系統(tǒng)以后,必須設(shè)置NSBaselineOffsetAttributeName屬性,否則文字上下不對(duì)齊
NSString *str = [NSString stringWithFormat:@"%zd~%zd %zd~%.f",surveyModel.point_s,surveyModel.point_c, surveyModel.point_s,surveyModel.point_c * 1.1];
NSRange range = [str rangeOfString:@" "];
NSMutableAttributedString *attriStr = [[NSMutableAttributedString alloc] initWithString:str];
//
[attriStr addAttribute:NSStrikethroughStyleAttributeName
value:[NSNumber numberWithInteger:NSUnderlineStyleSingle]
range:NSMakeRange(0,range.location)];
// iOS10.3系統(tǒng)以后 ,設(shè)置該屬性才顯示
[attriStr addAttribute:NSBaselineOffsetAttributeName
value:@(NSUnderlineStyleSingle)
range:NSMakeRange(0,attriStr.length)];
//
[attriStr addAttribute:NSForegroundColorAttributeName
value:[UIColor darkGrayColor]
range:NSMakeRange(0,range.location)];
[self.integralLabel setAttributedText:attriStr];
如果整個(gè)lable都有下?lián)Q線或斜線時(shí),不需要設(shè)置上述屬性
// 整個(gè)都有下劃線
NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:@"修改收貨地址" attributes:@{NSUnderlineStyleAttributeName : [NSNumber numberWithInteger:NSUnderlineStyleSingle]}];
self.modifyAddressL.attributedText = attStr;