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;
  • 相关阅读:
    ajax三级联动
    ajax基础
    pdo连接数据
    jquery选择器和基本语句
    会话
    封装连接类
    1218数据访问
    php登陆与注册
    数据库连接和乱码问题
    mysql 严格模式 Strict Mode说明(text 字段不能加默认或者 不能加null值得修改方法)
  • 原文地址:https://www.cnblogs.com/staRR-k2/p/5015637.html
Copyright © 2011-2022 走看看