zoukankan      html  css  js  c++  java
  • AttributedString-富文本字符串

     名字叫attributes并且是NSDictionary *类型的参数,它的key一般都有以下规律

     1.iOS7开始

     1> 所有的key都来源于: NSAttributedString.h

     2> 格式基本都是:NS***AttributeName

     

     2.iOS7之前

     1> 所有的key都来源于: UIStringDrawing.h

     2> 格式基本都是:UITextAttribute***

    实例:

    NSMutableDictionary *attrs = [NSMutableDictionary dictionary]; // 创建属性字典
        attrs[NSFontAttributeName] = [UIFont systemFontOfSize:15]; // 设置font
        if (white) {
            attrs[NSForegroundColorAttributeName] = [UIColor whiteColor];
        }else{
            attrs[NSForegroundColorAttributeName] = HKHexColor(0xff9B9B9B);
        }
        
    NSAttributedString *attStr = [[NSAttributedString alloc] initWithString:placeholder attributes:attrs]; // 初始化富文本占位字符串
    tf.attributedPlaceholder = attStr;

    //设置字体大小

    NSFontAttributeName

    //设置字体颜色,默认为黑色

    NSForegroundColorAttributeName

    //设置字体所在区域背景颜色

    NSBackgroundColorAttributeName

    //设置字体行间距

    NSParagraphStyleAttributeName

     

     

  • 相关阅读:
    ubuntu安装tftp服务
    ubuntu编译openwrt
    centos8更换阿里云yum源和epel源
    centos中samba共享设置
    centos7、8防火墙设置查询
    openwrt编译报错集锦
    python学习笔记--pip安装pyaudio库报错ERROR: Command errored out with exit status 1:解决办法
    python学习笔记---python3中Base64编码时参数不能为str
    python学习笔记---BeautifulSoup模块爬图
    centos系统时间修改
  • 原文地址:https://www.cnblogs.com/StevenHuSir/p/10106958.html
Copyright © 2011-2022 走看看