UILabel上的文字 单独改变 属性

    UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(0.065*UIScreenSize.width, backBtn.frame.origin.y + backBtn.frame.size.height, UIScreenSize.width - 0.12*UIScreenSize.width, 0.14*UIScreenSize.height)];
    label1.numberOfLines = 0;
    label1.font = [UIFont boldSystemFontOfSize:14];
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc]initWithString:@"请慎用加息卡,加息期间账户所有资金(包括新的投资资金)将被冻结,都不可提现,直至加息卡使用结束。"];
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(0, str.length)];
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor yellowColor] range:NSMakeRange(33, 4)];
    label1.attributedText = str;
    
    [navUI addSubview:label1];

效果图如下:


PS: 另附上别的修改的属性!

1. 改变字体类型或者字体大小

NSString *str = [NSString stringWithFormat:@"%@",cstr];
    NSMutableAttributedString *tmpStr = [[NSMutableAttributedString alloc]initWithString:str];
    [tmpStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13] range:NSMakeRange(0, str.length-1)];


2. 添加下划线

self.externBtn = [[UIButton alloc]init];
    NSMutableAttributedString *title = [[NSMutableAttributedString alloc] initWithString:@"跳过此步骤"];
    NSRange titleRange = {0,[title length]};
    [title addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:titleRange];
    [title addAttribute:NSForegroundColorAttributeName value:DefaultColor range:titleRange];
    [self.externBtn setAttributedTitle:title forState:UIControlStateNormal];

还有一些别的属性


更多资料


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值