天天看點

iOS-屬性字元串添加下劃線、删除線

常用到的屬性字元串

///定義屬性字元串
NSMutableAttributedString *att  = [[NSMutableAttributedString alloc]initWithString:@""];
///删除線
[att addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlineStyleSingle | NSUnderlineStyleSingle) range:NSMakeRange(0, 0)];
///字型大小
UIFont *font = [UIFont fontWithName:@"Helvetica-Bold" size:17.0];
[att addAttribute:NSFontAttributeName value:font range:NSMakeRange(0,0)];
///字型顔色
[att addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 0)];
// 下劃線
[att addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, 0)];      

直接賦給label就可以了