iOS 设置Label中特定的文字大小和颜色
直接上代碼:
_price = @"27";
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:_cookPrice.text];
//設置顏色
? ? [attributedString addAttribute:NSForegroundColorAttributeName value:[MCUtils colorWithRGBString:@"#FFA025"] range:NSMakeRange(0, _price.length)]; // 0為起始位置 length是從起始位置開始 設置指定顏色的長度
//設置尺寸
? ? [attributedString addAttribute:NSFontAttributeName value:kFont17 range:NSMakeRange(0, _price.length)];?// 0為起始位置 length是從起始位置開始 設置指定字體尺寸的長度
? ?//這段代碼必需要寫 否則沒效果
? ? _cookPrice.attributedText = attributedString;
轉載于:https://www.cnblogs.com/lxjshuju/p/6825874.html
總結
以上是生活随笔為你收集整理的iOS 设置Label中特定的文字大小和颜色的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android开发简易教程
- 下一篇: 工作笔记5