美文网首页
IOS UILabel文字添加下划线与中划线

IOS UILabel文字添加下划线与中划线

作者: FMaarten | 来源:发表于2018-12-26 10:03 被阅读0次
  • 添加下划线代码

    UILabel * underlab = [[UILabel alloc] initWithFrame:CGRectMake(20, 100, 200, 40)];
    [self.view addSubview:underlab];
    //添加下划线
    NSDictionary * underAttribtDic  = @{NSUnderlineStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleSingle],NSForegroundColorAttributeName:[UIColor redColor]};
    NSMutableAttributedString * underAttr = [[NSMutableAttributedString alloc] initWithString:@"12432" attributes:underAttribtDic];
    underlab.attributedText = underAttr;
效果图如下: under_line.png
  • 添加中划线代码

    UILabel * centerLab = [[UILabel alloc] initWithFrame:CGRectMake(20, 160, 200, 40)];
    [self.view addSubview:centerLab];
    //添加中划线
    NSDictionary * centerAttribtDic = @{NSStrikethroughStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleSingle],NSForegroundColorAttributeName:[UIColor redColor]};
    NSMutableAttributedString * centerAttr = [[NSMutableAttributedString alloc] initWithString:@"12432" attributes:centerAttribtDic];
    centerLab.attributedText = centerAttr;
效果图如下: center_line.png

相关文章

网友评论

      本文标题:IOS UILabel文字添加下划线与中划线

      本文链接:https://www.haomeiwen.com/subject/ooiclqtx.html