zoukankan      html  css  js  c++  java
  • 富文本(NSMutableAttributedString)

    干货:

    - (void)viewDidLoad {

        [super viewDidLoad];

        

        NSString * tempStr = @"貌似这个叫富文本";

        NSMutableAttributedString * attStr = [self stringTurnToAttributeStringWithString:tempStr

                                                                                    Font:25

                                                                               TextColor:[UIColor redColor]

                                                                                   Range:NSMakeRange(5, 3)];

        UILabel * label = [[UILabel alloc] initWithFrame:self.view.bounds];

        label.textAlignment = NSTextAlignmentCenter;

        label.attributedText = attStr;

        [self.view addSubview:label];

    }

    - (NSMutableAttributedString *)stringTurnToAttributeStringWithString:(NSString *)string

                                                                    Font:(CGFloat)fontSize

                                                               TextColor:(UIColor *)textColor

                                                                   Range:(NSRange)range{

        NSMutableAttributedString * attStr = [[NSMutableAttributedString alloc] initWithString:string];

        [attStr addAttributes:@{NSForegroundColorAttributeName:textColor,

                                NSFontAttributeName:[UIFont systemFontOfSize:fontSize]}

                        range:range];

        return attStr;

    }

  • 相关阅读:
    数组名与指向数组的指针
    如何实现带可变长参数的函数
    assert()的使用
    参数入栈的顺序以及栈/堆的生长顺序
    指向函数的指针
    各变量入栈顺序
    数组与指针
    C中空指针、NULL与0
    C中为什么不能用==比较字符串?
    在命令行窗口中输入EOF
  • 原文地址:https://www.cnblogs.com/Mr-------Li/p/5640263.html
Copyright © 2011-2022 走看看