直接上代碼
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 200, 100)];
[self.view addSubview:label];
NSAttributedString *attributedString = [[NSAttributedString alloc]initWithString:@"10000¥"
attributes:
@{NSFontAttributeName:[UIFont systemFontOfSize:20.f],//設(shè)置字體大小
NSForegroundColorAttributeName:[UIColor greenColor],//設(shè)置字體顏色
NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle|NSUnderlinePatternSolid),//設(shè)置刪除線樣式
NSStrikethroughColorAttributeName:[UIColor redColor]}];//設(shè)置刪除線顏色
label.attributedText = attributedString;
label.font = [UIFont systemFontOfSize:36 weight:50];
效果圖
UILabel添加刪除線