给Label加下划线中划线

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了给Label加下划线中划线相关的知识,希望对你有一定的参考价值。

添加中划线:

        UILabel * strikeLabel = [[UILabel alloc] initWithFrame:(CGRectMake(10, 10, 50, 30))];

        NSString *textStr = [NSString stringWithFormat:@"%@", @"12"];

        

        //中划线

        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:@"%@", @"12"];

        

        // 下划线

        NSDictionary *attribtDic = @{NSUnderlineStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};

        NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:textStr attributes:attribtDic];

        

        //赋值

        underlineLabel.attributedText = attribtStr;

        

        [self.view addSubview:underlineLabel];

以上是关于给Label加下划线中划线的主要内容,如果未能解决你的问题,请参考以下文章