0
点赞
收藏
分享

微信扫一扫

iOS开发 给Label加下划线、中划线

添加中划线:  

​​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];​​

添加下划线: 

 

 

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];​​

举报

相关推荐

0 条评论