iOS学习-如何缩进UILabel的第二行,并设置不同字体与颜色

当文字过长时,需要让UILabel换行缩进,可采取以下方法,headIndent根据自己的需要设置

    NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
    style.headIndent = 17;
    NSDictionary *attributes = @{ NSParagraphStyleAttributeName: style};
    NSMutableAttributedString *richText = [[NSMutableAttributedString alloc] initWithString:@"1.  与xxxxxxx离得太远,建议将手机靠近床后重新搜索;\n2. xxxxxxxxxxxxx未通电,检查是否异常;\n3. xxxxxxxxxxxxxxx已被他人连接,让他人断开设备取消连接后,重新搜索;\n4. 手机蓝牙断开,重新开启蓝牙并搜索。" attributes:attributes];
    //根据下标索引设置字体颜色
    [richText addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(9, 2)];
    //根据下标索引设置字体样式大小(式样只对字母有效)
    [richText addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial-BoldItalicMT" size:30.0] range:NSMakeRange(0, 5)];
    reasonContent.attributedText = richText;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值