NSString 属性更改合集
来源:互联网 发布:爱上一个中国女人知乎 编辑:程序博客网 时间:2024/05/17 10:55
前言
我们经常碰到更改UILabel等控件字体样式,像更改行距,个别字体变色,个别字体变大,字体加边框等,这里将碰到的一些情况进行总结。
所有的Key
NSFontAttributeName; //字体,value是UIFont对象NSParagraphStyleAttributeName;//绘图的风格(居中,换行模式,间距等诸多风格),value是NSParagraphStyle对象NSForegroundColorAttributeName;// 文字颜色,value是UIFont对象NSBackgroundColorAttributeName;// 背景色,value是UIFontNSLigatureAttributeName; // 字符连体,value是NSNumberNSKernAttributeName; // 字符间隔NSStrikethroughStyleAttributeName;//删除线,value是NSNumberNSUnderlineStyleAttributeName;//下划线,value是NSNumberNSStrokeColorAttributeName; //描绘边颜色,value是UIColorNSStrokeWidthAttributeName; //描边宽度,value是NSNumberNSShadowAttributeName; //阴影,value是NSShadow对象NSTextEffectAttributeName; //文字效果,value是NSStringNSAttachmentAttributeName;//附属,value是NSTextAttachment 对象NSLinkAttributeName;//链接,value是NSURL or NSStringNSBaselineOffsetAttributeName;//基础偏移量,value是NSNumber对象NSUnderlineColorAttributeName;//下划线颜色,value是UIColor对象NSStrikethroughColorAttributeName;//删除线颜色,value是UIColorNSObliquenessAttributeName; //字体倾斜NSExpansionAttributeName; //字体扁平化NSVerticalGlyphFormAttributeName;//垂直或者水平,value是 NSNumber,0表示水平,1垂直
常用设置
//创建字典存储属性 NSMutableDictionary *attributes = [NSMutableDictionary dictionary];//1.更改大小 [attributes setValue:[UIFont systemFontOfSize:15] forKey:NSFontAttributeName];//2.字体颜色 [attributes setValue:[UIColor whiteColor] forKey:NSForegroundColorAttributeName]; //3.背景色 [attributes setValue:[UIColor grayColor] forKey:NSBackgroundColorAttributeName]; //4.设置描边 [attributes setValue:[UIColor grayColor] forKey:NSStrokeColorAttributeName]; [attributes setValue:@(2.0) forKey:NSStrokeWidthAttributeName];//添加到string上 NSAttributedString *attri = [[NSAttributedString alloc] initWithString:string attributes:attributes];//用法label.attributedText = attri;
//第二种简单写法
//简易写法 NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:string]; [attributeString addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15],NSBackgroundColorAttributeName:[UIColor whiteColor]} range:NSMakeRange(0, attributeString.length)];//用法label.attributedText = attributeString;
更多用法参考:http://blog.csdn.net/hello_hwc/article/details/46731991
阅读全文
0 0
- NSString 属性更改合集
- css属性合集
- 常用控件属性合集
- NSString类型的更改大小写
- NSString的属性相关
- NSString的copy 属性
- CSS属性合写
- Android动画合集之属性动画-初见
- Android动画合集之属性动画-又见
- NSString copy和retain属性
- 体会NSString的copy属性
- NSString常用属性和用法
- NSString基本属性和方法
- NSString字符串的pathExtension属性
- 使用COPY声明NSSTRING属性
- 使用COPY声明NSSTRING属性
- 为什么NSString属性使用copy
- 动态更改class属性
- PHP常见排序算法整理学习
- cocoaPods安装2017 以及遇到的坑
- Caused by: org.elasticsearch.search.query.QueryPhaseExecutionException: Result window is too large,
- 压缩感知重构算法之正则化正交匹配追踪(ROMP)
- tensorflow nan
- NSString 属性更改合集
- 理解OAuth 2.0
- error C1128:字节数超过对象文件格式main.cpp限制:请使用/bigobj进行编译
- bzoj 3195: [Jxoi2012]奇怪的道路 状压dp
- c++函数重载
- 面向对象设计原则
- 函数调用栈 剖析+图解
- javawebday18
- Linux中静态库和共享库的区别