iOS开发文字上面加横线

ios开发在文字上面加横线的实现:

1
- (void)viewDidLoad { 2 [super viewDidLoad]; 3 // Do any additional setup after loading the view, typically from a nib. 4 5 6 UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 200, 50)]; 7 lab.text = @"123122222222123213"; 8 lab.textColor = [UIColor redColor]//改变textColor就可以改变横线的颜色 9 [self.view addSubview:lab]; 10 NSMutableAttributedString *marketPrice = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"¥%@",lab.text]]; 11 [marketPrice addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:NSMakeRange(0, marketPrice.length)]; 12 lab.attributedText = marketPrice; 13 14 15 16 }

实现这些代码就 ok了 !!!

运行效果:

posted on 2015-10-29 14:51  Smile_闪电  阅读(693)  评论(0编辑  收藏  举报

导航