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

     

     

  • 相关阅读:
    iOS开发-UINavigationController简单介绍
    iOS开发-UITableView表格优化
    iOS开发-UITableView常用方法
    iOS开发-数据选择UIPickerView
    iOS开发-照片选择
    The Best KPIs to Use in Your Company
    IIS webService 并发 性能
    转---CentOS安装Oracle数据库详细介绍及常见问题汇总
    oracle rac的启动与停止
    [转] nginx配置优化+负载均衡+动静分离(附带参数解析)
  • 原文地址:https://www.cnblogs.com/StevenHuSir/p/10106958.html
Copyright © 2011-2022 走看看