• iOS 设置文本中指定某段文本的颜色 大小


    NSString *money = @"300";

            NSString *perStr = @"元/时";

            NSString *text = [NSString stringWithFormat:@"%@%@",money,perStr];

            if ([self.currentPriceLabel respondsToSelector:@selector(setAttributedText:)]) {

                NSDictionary *attribs = @{

                                          NSForegroundColorAttributeName:self.currentPriceLabel.textColor,

                                          NSFontAttributeName:self.currentPriceLabel.font

                                          };

                NSMutableAttributedString *attributedText =

                [[NSMutableAttributedString alloc] initWithString:text

                                                       attributes:attribs];

                

                // Red text attributes

                //#5773de

                UIColor *aColor = RED_COLOR;

                NSRange redTextRange =[text rangeOfString:money];// * Notice that usage of rangeOfString in this case may cause some bugs - I use it here only for demonstration

                [attributedText setAttributes:@{NSForegroundColorAttributeName:aColor,NSFontAttributeName:[UIFontboldSystemFontOfSize:16]} range:redTextRange];

                self.currentPriceLabel.attributedText = attributedText;

            }

  • 相关阅读:
    HDU 3709 数位dp
    Educational Codeforces Round 64 (Rated for Div. 2)-C. Match Points
    POJ 1845乘法逆元+约数和
    POJ3696 欧拉定理
    NC24953 树形dp(最小支配集)
    Codeforces 1173 C 思维+模拟
    Codeforces 1324F 树形dp+换根
    codeforces-1285D(字典树)
    面向纯小白的CLion(C++)基于Windows的安装配置教程
    HDU-2825Wireless Password(AC自动机+状压DP)
  • 原文地址:https://www.cnblogs.com/ycblog/p/5162857.html
Copyright © 2020-2023  润新知