zoukankan      html  css  js  c++  java
  • 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;

            }

  • 相关阅读:
    JAVA7/8中的HashMap和ConrrentMap
    Redis
    SpringBoot
    JAVA反射优化
    spring多模块项目手动整合
    spring事物与传播行为
    [pixhawk笔记]7-MAVLink添加自定义消息
    [pixhawk笔记]6-uORB流程及关键函数解析
    [pixhawk笔记]5-uORB消息传递
    [pixhawk笔记]4-如何写一个简单的应用程序
  • 原文地址:https://www.cnblogs.com/ycblog/p/5162857.html
Copyright © 2011-2022 走看看