代码中在Label上添加删除线方法

在代码中在Label上添加删除线方法

其他的不多说,直接上代码。

UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(50, 50, 80, 30)];
    [self.view addSubview:lable];
    lable.backgroundColor = [UIColor redColor];
    lable.textAlignment = NSTextAlignmentCenter;
    NSString *deleteStr = @"delete";
    NSUInteger length = [deleteStr length];

    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:deleteStr];
    [attri addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:NSMakeRange(0, length)];
    [attri addAttribute:NSStrikethroughColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, length)];
    [lable setAttributedText:attri]; 

你可能感兴趣的:(iOS,label)