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

 

 

猜你喜欢

转载自www.cnblogs.com/StevenHuSir/p/10106958.html
今日推荐