怎么用NSAttributedString画下划线

这篇文章将为大家详细讲解有关怎么用NSAttributedString画下划线,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(20, 60, 100, 30)];

    [self.view addSubview:lable];

    lable.backgroundColor = [UIColor redColor];

    lable.textAlignment = NSTextAlignmentCenter;

    NSString *oldPrice = @"¥ 999999";

    NSUInteger length = [oldPrice length];

    [self.view addSubview:lable];

    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:oldPrice];

    [attri addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:NSMakeRange(0, length)];

    [attri addAttribute:NSStrikethroughColorAttributeName value:[UIColor yellowColor] range:NSMakeRange(0, length)];

    [lable setAttributedText:attri];

关于“怎么用NSAttributedString画下划线”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。