UILabel 添加下划线 中划线

UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 200, 30)];

    label1.text=@"中划线";

    label1.textColor = [UIColor lightGrayColor];

    NSDictionary *attributeDict = @{NSStrikethroughStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleSingle]};

    NSMutableAttributedString*attributeStr = [[NSMutableAttributedStringalloc]initWithString:label1.textattributes:attributeDict];

    label1.attributedText= attributeStr;


    [self.viewaddSubview:label1];




    UILabel*label2 = [[UILabelalloc]initWithFrame:CGRectMake(100,200,200,30)];

    label2.text=@"下划线";

    label2.textColor = [UIColor lightGrayColor];

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

    NSMutableAttributedString*attributeStr2 = [[NSMutableAttributedStringalloc]initWithString:label2.textattributes:attributeDict2];

    label2.attributedText= attributeStr2;


    [self.viewaddSubview:label2];


UILabel 添加下划线 中划线_第1张图片

你可能感兴趣的:(UILabel 添加下划线 中划线)