zoukankan      html  css  js  c++  java
  • iOS

    1. 初始化

    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"YOUR_STRING"];

    还有一种初始化方法,直接在初始化时给String赋属性值:

    - (instancetype)initWithString:(NSString *)str attributes:(nullable NSDictionary<NSString *, id> *)attrs;

    2. 给String赋属性值

    例如,把前4位字符字体颜色改为红色:

    [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 3)];

    3. 常见的属性名

    NSFontAttributeName  字体

    NSParagraphStyleAttributeName  段落格式 

    NSForegroundColorAttributeName  字体颜色

    NSBackgroundColorAttributeName   背景颜色

    NSStrikethroughStyleAttributeName 删除线格式

    NSUnderlineStyleAttributeName      下划线格式

    NSStrokeColorAttributeName        删除线颜色

    NSStrokeWidthAttributeName 删除线宽度

    NSShadowAttributeName  阴影

    PS: 可以讲多个属性置于NSDictionary中,再用addAttributes函数给字符串赋予属性值

    - (void)addAttributes:(NSDictionary<NSString *, id> *)attrs range:(NSRange)range;
  • 相关阅读:
    GAN 的推导、证明与实现。
    WGAN学习笔记
    常用损失函数积累
    交叉熵在loss函数中使用的理解
    贝叶斯决策
    极大似然估计
    gated pixelCNN。
    三叉搜索树 转载
    Rabin-Karp 字符串匹配算法
    面试题整理 转载
  • 原文地址:https://www.cnblogs.com/staRR-k2/p/5015637.html
Copyright © 2011-2022 走看看