美文网首页
带下划线的label 和 button

带下划线的label 和 button

作者: IreneWang1988 | 来源:发表于2018-08-31 14:02 被阅读0次

NSString *str = @"您也可以手动输入MAC地址";

    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:str];

    // Add attribute NSUnderlineStyleAttributeName

    [attributedStringaddAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleSingle] range:NSMakeRange(0, str.length)];

    [attributedStringaddAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13] range:NSMakeRange(0, str.length)];

    [attributedStringaddAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(0, 4)];

    [attributedStringaddAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRGBHex:0X428aea] range:NSMakeRange(4, str.length-4)];

    CGSize  size = [strsizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]}];

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-size.width)/2, SCREEN_HEIGHT-80,size.width, 50)];

    [labelsetLineBreakMode:NSLineBreakByWordWrapping];

    [labelsetBackgroundColor:[UIColor clearColor]];

    [labelsetTextAlignment:NSTextAlignmentCenter];

    [labelsetAttributedText:attributedString];

  //  [bgView addSubview:label];

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

    [buttonsetAttributedTitle:attributedString forState: UIControlStateNormal];

    button.frame=CGRectMake((SCREEN_WIDTH-size.width)/2,SCREEN_HEIGHT-80,size.width,50);

    [buttonaddTarget:self action:@selector(typeMacAddress) forControlEvents:UIControlEventTouchUpInside];

    [bgViewaddSubview:button];

相关文章

网友评论

      本文标题:带下划线的label 和 button

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