1.NSKernAttributeName: @10 调整字句 kerning 字句调整

2.NSFontAttributeName : [UIFont systemFontOfSize:_fontSize] 设置字体

3.NSForegroundColorAttributeName :[UIColor redColor] 设置文字颜色

4.NSParagraphStyleAttributeName : paragraph 设置段落样式

5.NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];

paragraph.alignment = NSTextAlignmentCenter;

6.NSBackgroundColorAttributeName: [UIColor blackColor] 设置背景颜色

7.NSStrokeColorAttributeName设置文字描边颜色,需要和NSStrokeWidthAttributeName设置描边宽度,这样就能使文字空心.

NSStrokeWidthAttributeName这个属性所对应的值是一个 NSNumber 对象(小数)。该值改变描边宽度(相对于字体size 的百分比)。默认为 0,即不改变。正数只改变描边宽度。负数同时改变文字的描边和填充宽度。例如,对于常见的空心字,这个值通常为3.0。

同时设置了空心的两个属性,并且NSStrokeWidthAttributeName属性设置为整数,文字前景色就无效果了

效果:

效果:

8. NSStrikethroughStyleAttributeName 添加删除线,strikethrough删除线

效果:

9. NSUnderlineStyleAttributeName 添加下划线

效果:

10. NSShadowAttributeName 设置阴影,单独设置不好使,必须和其他属性搭配才好使。

和这三个任一个都好使,NSVerticalGlyphFormAttributeName,NSObliquenessAttributeName,NSExpansionAttributeName

11.NSVerticalGlyphFormAttributeName

该属性所对应的值是一个 NSNumber 对象(整数)。0 表示横排文本。1 表示竖排文本。在 iOS 中,总是使用横排文本,0 以外的值都未定义。

效果:

12. NSObliquenessAttributeName设置字体倾斜。Skew 斜

效果:

13. NSExpansionAttributeName 设置文本扁平化

效果:

在项目开发中,我们经常会遇到在这样一种情形:在一个UILabel 使用不同的颜色或不同的字体来体现字符串,在iOS 6 以后我们可以很轻松的实现这一点,官方的API 为我们提供了UILabel类的attributedText, 使用不同颜色和不同字体的字符串,我们可以使用NSAttributedText 和 NSMutableAttributedText 类来实现。

现实代码:

.h 文件

1 @interface ViewController : UIViewController
2 @property (nonatomic, strong) IBOutlet UILabel *attrLabel;
3 - (IBAction)next:(id)sender;
4 @end

.m文件 在viewDidLoad方法中添加以下代码:

1 self.title = @"For iOS 6 & later";
2 NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"Using NSAttributed String"];
3 [str addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,5)];
4 [str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(6,12)];
5 [str addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(19,6)];
6 [str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial-BoldItalicMT"
size:30.0] range:NSMakeRange(0, 5)];
7 [str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold"
size:30.0] range:NSMakeRange(6, 12)];
8 [str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Courier-BoldOblique"
size:30.0] range:NSMakeRange(19, 6)];
9 attrLabel.attributedText = str;

效果图:

如果想在iOS6.0以前版本实现这个效果,需要使用到一个第三方库TTTAttributedLabel,同时还有导入CoreText.frame框架.

iOS之文本属性Attributes的使用的更多相关文章

  1. iOS基础 - 文本属性Attributes

    NSKernAttributeName: 调整字句 kerning 字句调整 NSFontAttributeName : [UIFont systemFontOfSize:_fontSize] 设置字 ...

  2. iOS中文本属性Attributes

    NSFontAttributeName //设置字体大小 NSParagraphStyleAttributeName //设置段落格式 NSForegroundColorAttributeName / ...

  3. 给iOS开发新手送点福利,简述文本属性Attributes的用法

    给iOS开发新手送点福利,简述文本属性Attributes的用法   文本属性Attributes 1.NSKernAttributeName: @10 调整字句 kerning 字句调整 2.NSF ...

  4. IOS开发UI基础文本属性Attributes

    文本属性Attributes 1.NSKernAttributeName: @10 调整字句 kerning 字句调整 2.NSFontAttributeName : [UIFont systemFo ...

  5. iOS- 详解文本属性Attributes(转)

    iOS- 详解文本属性Attributes 1.NSKernAttributeName: @10 调整字句 kerning 字句调整 2.NSFontAttributeName : [UIFont s ...

  6. zencart批量插入TEXT文本属性attributes

    有时候上传的产品与多级分类比较多,在后台添加文本属性如Name,Number等需要顾客自定义的内容就比较费神了.现在只需将以下代码保存为insert_attributes.php,变量$options ...

  7. 文本属性Attributes

    1.NSKernAttributeName: @10 调整字句 kerning 字句调整 2.NSFontAttributeName : [UIFont systemFontOfSize:_fontS ...

  8. iOS- 详解文本属性Attributes

    1.NSKernAttributeName: @10 调整字句 kerning 字句调整 2.NSFontAttributeName : [UIFont systemFontOfSize:_fontS ...

  9. 【转】iOS- 详解文本属性Attributes

    原文: http://www.cnblogs.com/qingche/p/3574995.html?utm_source=tuicool 1.NSKernAttributeName: @10 调整字句 ...

随机推荐

  1. 设计模式_Visitor_访问者模式

    形象例子: 情人节到了,要给每个MM送一束鲜花和一张卡片,可是每个MM送的花都要针 对她个人的特点,每张卡片也要根据个人的特点来挑,我一个人哪搞得清楚,还是找花店老板和礼品店老板做一下Visitor, ...

  2. Hadoop中Combiner的作用

    1.Partition 把 Map任务输出的中间结果按 key的范围划分成 R份( R是预先定义的 Reduce任务的个数),划分时通常使用hash函数如: hash(key) mod R,这样可以保 ...

  3. mysql日期加减问题

    有一个date列,我想修改下,让该列里每个日期都加上7天,怎么写代码?  update [表名] set date=date_add(date, interval 7 day); SELECT * f ...

  4. 【Hadoop代码笔记】Hadoop作业提交之TaskTracker获取Task

    一.概要描述 在上上一篇博文和上一篇博文中分别描述了jobTracker和其服务(功能)模块初始化完成后,接收JobClient提交的作业,并进行初始化.本文着重描述,JobTracker如何选择作业 ...

  5. [假期总结]Self

    8月底返校,这一周也没有勤学苦练.假期3周的时间学习了nodejs. 1.nodejs的学习 学习了一本书上的例程,搭建了个博客.这种程度等于是能够动手开发的阶段,前路还很漫长. 2.个人网站的建设 ...

  6. 曝光卖假币的店铺和旺旺ID

    1:店铺名称:九玖邮币 掌柜ID:九玖邮币[此人较贼,价格只比我们低一点,图用的不太清晰的,或者直接用真品图,而且卖假币卖到2钻了,很多人上当了.]1.5 店铺名称:聚鑫钱币 掌柜ID:聚鑫钱币 [1 ...

  7. homework-02 一坑到底的最大和联通图

    你在这个作业中学到了什么?  有什么好的设计值得分享?  感想如何 (太容易 / 太难 / 太无趣)? 我觉得这套题目有点偏难,我不像大牛那样,有很多算法可以选择,我是0算法基础的,所以遇到这题我一个 ...

  8. 射频识别技术漫谈(2)——国际标准【worldsing 笔记】

    如果你只是智能卡的用户,通常可以不必关注国际标准,但作为智能卡的专业开发人员,则至少也要对相关标准有所了解.国际标准一般都是西方人制定的,原版都是英文的,而所谓中文版往往是对原版的直译,许多情况下并未 ...

  9. jQuery插件- Autocomplete应用详解

    项目中有时会用到自动补全查询,就像Google搜索框.淘宝商品搜索功能,输入汉字或字母,则以该汉字或字母开头的相关条目会显示出来供用户选择, autocomplete插件就是完成这样的功能. auto ...

  10. 在线性级别时间内找出无序序列中的第k个元素

    在一个无序序列中找出第k个元素,对于k很小或者很大时可以采取特殊的方法,比如用堆排序来实现 .但是对于与序列长度N成正比的k来说,就不是一件容易的事了,可能最容易想到的就是先将无序序列排序再遍历即可找 ...