UILabel添加刪除線的效果(類似于商品促銷價(jià)格的效果)

直接上代碼

 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添加刪除線
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容