给Label加下划线、中划线ios

2017-02-17  本文已影响0人  ios小正太

添加中划线:UILabel* strikeLabel = [[UILabelalloc] initWithFrame:(CGRectMake(10,10,50,30))];NSString*textStr = [NSStringstringWithFormat:@"%@元", primeCost];//中划线NSDictionary*attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumbernumberWithInteger:NSUnderlineStyleSingle]};NSMutableAttributedString*attribtStr = [[NSMutableAttributedStringalloc]initWithString:textStr attributes:attribtDic];// 赋值strikeLabel.attributedText = attribtStr;  [self.view addSubview:strikeLabel];

添加下划线:UILabel*underlineLabel = [[UILabelalloc] initWithFrame:(CGRectMake(10,10,50,30))];NSString*textStr = [NSStringstringWithFormat:@"%@元", primeCost];// 下划线NSDictionary*attribtDic = @{NSUnderlineStyleAttributeName: [NSNumbernumberWithInteger:NSUnderlineStyleSingle]};NSMutableAttributedString*attribtStr = [[NSMutableAttributedStringalloc]initWithString:textStr attributes:attribtDic];//赋值underlineLabel.attributedText = attribtStr;  [self.view addSubview:underlineLabel];

上一篇 下一篇

猜你喜欢

热点阅读