iOS開發 給Label加下划線、中划線


添加中划線:  

0
1
02
03
04
05
06
07
08
09
10
11
UILabel * strikeLabel = [[UILabel alloc] initWithFrame:(CGRectMake(10, 10, 50, 30))];
NSString *textStr = [ NSString stringWithFormat: @"%@元" , primeCost];
 
//中划線
NSDictionary *attribtDic = @{ NSStrikethroughStyleAttributeName : [ NSNumber numberWithInteger: NSUnderlineStyleSingle ]};
NSMutableAttributedString *attribtStr = [[ NSMutableAttributedString alloc]initWithString:textStr attributes:attribtDic];
 
// 賦值
strikeLabel.attributedText = attribtStr;
 
[ self .view addSubview:strikeLabel];
添加下划線: 
 
 
01
02
03
04
05
06
07
08
09
10
11
UILabel *underlineLabel = [[UILabel alloc] initWithFrame:(CGRectMake(10, 10, 50, 30))];
NSString *textStr = [ NSString stringWithFormat: @"%@元" , primeCost];
 
// 下划線
NSDictionary *attribtDic = @{ NSUnderlineStyleAttributeName : [ NSNumber numberWithInteger: NSUnderlineStyleSingle ]};
NSMutableAttributedString *attribtStr = [[ NSMutableAttributedString alloc]initWithString:textStr attributes:attribtDic];
 
//賦值
underlineLabel.attributedText = attribtStr;
 
[ self .view addSubview:underlineLabel];


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM