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;

    }

  • 相关阅读:
    http经典解析
    js实现canvas保存图片为png格式并下载到本地
    你所不知的 CSS ::before 和 ::after 伪元素用法
    js自动下载
    CSS 实现隐藏滚动条同时又可以滚动
    checkbox与文字对齐
    利用html2canvas截图,得到base64上传ajax
    bootstrap-datepicker简单使用
    移动端禁止滚动
    h5移动网页唤起App
  • 原文地址:https://www.cnblogs.com/Mr-------Li/p/5640263.html
Copyright © 2011-2022 走看看