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

2018-12-26  本文已影响0人  FMaarten
  • 添加下划线代码

    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
上一篇 下一篇

猜你喜欢

热点阅读