ios6之前在一个字符串中如果也让某个字体高亮或者特殊显示(如: 关注[ ]),需要用单独一个的标签进行显示,或者利用CoreText进行字体绘绘制,非常麻烦;

现在IOS6 中TextView,label,textField中新增了这样的一个属性NSAttributedString  只能应用IOS6

@property(nonatomic,copy) NSAttributedString *attributedText NS_AVAILABLE_IOS(6_0); // default is nil

利用NSAttributedString构建一个新的属性字符串,你就可以对他进行操作,删除,增加,字体格式化,设置某个字符前景色,字体颜色等...

如上图所示,直接上代码

- (void)setupTextView
{
_textView = [[UITextView alloc] initWithFrame:self.view.frame];
self.textView.textColor = [UIColor blackColor];
self.textView.font = [UIFont fontWithName:@"Arial" size:18.0];
self.textView.delegate = self;
self.textView.backgroundColor = [UIColor whiteColor];
self.textView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; NSString *textToAdd = @"Now is the time for all good developers to come to serve their country.\n\nNow is the time for all good developers to come to serve their country.\r\rThis text view can also use attributed strings."; NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:textToAdd]; // make red text
[attrString addAttribute:NSForegroundColorAttributeName
value:[UIColor redColor]
range:NSMakeRange([attrString length] - 19, 19)]; // make blue text
[attrString addAttribute:NSForegroundColorAttributeName
value:[UIColor blueColor]
range:NSMakeRange([attrString length] - 23, 3)];
[attrString addAttribute:NSUnderlineStyleAttributeName
value:[NSNumber numberWithInteger:1]
range:NSMakeRange([attrString length] - 23, 3)]; [self.textView setAttributedText:attrString]; self.textView.returnKeyType = UIReturnKeyDefault;
self.textView.scrollEnabled = YES; [self.view addSubview:self.textView];
}

NSForegroundColorAttributeName // 代表字体的前景色  下面所有进行字体格式化的标签

/* Predefined character attributes for text. If the key is not in the dictionary, then use the default values as described below.

*/

UIKIT_EXTERN NSString *const NSFontAttributeName NS_AVAILABLE_IOS(_0);                // UIFont, default Helvetica(Neue) 12

UIKIT_EXTERN NSString *const NSParagraphStyleAttributeName NS_AVAILABLE_IOS(_0);      // NSParagraphStyle, default defaultParagraphStyle

UIKIT_EXTERN NSString *const NSForegroundColorAttributeName NS_AVAILABLE_IOS(_0);     // UIColor, default blackColor

UIKIT_EXTERN NSString *const NSBackgroundColorAttributeName NS_AVAILABLE_IOS(_0);     // UIColor, default nil: no background

UIKIT_EXTERN NSString *const NSLigatureAttributeName NS_AVAILABLE_IOS(_0);            // NSNumber containing integer, default 1: default ligatures, 0: no ligatures, 2: all ligatures (Note: 2 is unsupported on iOS)

UIKIT_EXTERN NSString *const NSKernAttributeName NS_AVAILABLE_IOS(_0);                // NSNumber containing floating point value, in points; amount to modify default kerning. 0 means kerning is disabled. (note: values other than nil and 0 are unsupported on iOS)

UIKIT_EXTERN NSString *const NSStrikethroughStyleAttributeName NS_AVAILABLE_IOS(_0);  // NSNumber containing integer, default 0: no strikethrough

UIKIT_EXTERN NSString *const NSUnderlineStyleAttributeName NS_AVAILABLE_IOS(_0);      // NSNumber containing integer, default 0: no underline

UIKIT_EXTERN NSString *const NSStrokeColorAttributeName NS_AVAILABLE_IOS(_0);         // UIColor, default nil: same as foreground color

UIKIT_EXTERN NSString *const NSStrokeWidthAttributeName NS_AVAILABLE_IOS(_0);         // NSNumber containing floating point value, in percent of font point size, default 0: no stroke; positive for stroke alone, negative for stroke and fill (a typical value for outlined text would be 3.0)

UIKIT_EXTERN NSString *const NSShadowAttributeName NS_AVAILABLE_IOS(_0);              // NSShadow, default nil: no shadow

/* An NSNumber containing an integer value.  0 means horizontal text.  1 indicates vertical text.  If not specified, it could follow higher-level vertical orientation settings.  Currently on iOS, it's always horizontal.  The behavior for any other value is undefined.

*/

UIKIT_EXTERN NSString *const NSVerticalGlyphFormAttributeName NS_AVAILABLE_IOS(_0);

IOS6 字体高亮显示的更多相关文章

  1. Python学习-终端字体高亮显示1

    Python学习-终端字体高亮显示   1.采用原生转义字符序列,对Windows有的版本不支持(比如win7),完美支持Linux 实现过程: 终端的字符颜色是用转义序列控制的,是文本模式下的系统显 ...

  2. Python学习-终端字体高亮显示

    1.采用原生转义字符序列,对Windows有的版本不支持(比如win7),完美支持Linux 实现过程: 终端的字符颜色是用转义序列控制的,是文本模式下的系统显示功能,和具体的语言无关. 转义序列是以 ...

  3. ios开发之 -- NSString指定字体高亮显示

    一个简单的小需求,就是在一个字符串里面,指定一部分字节高亮显示,代码如下: NSString *descStr = @"需要高亮显示的字符"; NSString *nickStr ...

  4. 精品自用IDEA插件吐血推荐

    Alibaba Java Coding Guidelines 该插件集成了Alibaba代码编程规范,可以帮你找出你的代码怪味道 .gitignore 当你使用Git作为版本工具的时候,想要快速的添加 ...

  5. [C1W3] Neural Networks and Deep Learning - Shallow neural networks

    第三周:浅层神经网络(Shallow neural networks) 神经网络概述(Neural Network Overview) 本周你将学习如何实现一个神经网络.在我们深入学习具体技术之前,我 ...

  6. java学习笔记(2)注释、public lcass、class、标识符、字面值、变量

    java学习笔记(1)中说过了java的一些基础知识,发展史,特点,编译和运行过程,配置环境变量等,接下来开始介绍java的语法等只是点  关于java源程序中的注释: *什么是注释?注释的作用是什么 ...

  7. iOS 在UILabel显示不同的字体和颜色(ios6 and later)

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

  8. 兼容PC手机端字体

    各平台的主流字体支持情况 各系统的默认字体和常用字体: 系统 默认西文字体 默认中文字体 其他常用西文字体 其他常用中文字体 Windows 宋体 宋体 Tahoma.Arial.Verdana.Ge ...

  9. iOS6、7、8、9新特性汇总和适配说明

    iOS6新特性 一.关于内存警告 ios6中废除了viewDidUnload,viewWillUnload这两个系统回调,收到内存警告时在didReceiveMemoryWarning中进行相关的处理 ...

随机推荐

  1. codevs 1172 Hankson 的趣味题

    woc....这题考细节处理.要注意代码的逻辑顺序还有不要作死地循环到sqrt+1. #include<iostream> #include<cstdio> #include& ...

  2. iOS应用的crash日志的分析基础

        Outline如何获得crash日志如何解析crash日志如何分析crash日志     1. iOS策略相关     2. 常见错误标识     3. 代码bug 一.如何获得crash日志 ...

  3. linux - markdown编辑器

    1. linux可以用web-qq,http://web2.qq.com,[我们从未放弃成长,这句话挺感动我的.] (禽兽!你怎么在一开始就跑题!?) ————我只要“及时预览”———— 2. htt ...

  4. zoj 3659 Conquer a New Region

    // 给你一颗树 选一个点,从这个点出发到其它所有点的权值和最大// i 到 j的最大权值为 i到j所经历的树边容量的最小值// 第一感觉是树上的dp// 后面发现不可以// 看了题解说是并查集// ...

  5. Java基础——异常处理

    异常的层次结构 所有的异常类都是 java.lang.Exception 类的子类型.异常类都是 Throwable 类的子类.除了异常类 Error 类也是由 Throwable 类产生的的子类1. ...

  6. 关于web安全

    从技术到安全, 这是一个趋势. 以前追求的是比较炫酷的技术, 等实现过后发现, 自己还能做什么. 炫技完了之后,差不多就该到悟道的时候了. 用户安全, 就是一个很大的禅. 苹果拒绝 FBI, goog ...

  7. node.js study: cluster

    从v0.6.x开始,Node.js提供了多进程模块cluster,允许创建一组进程来共享同一个socket,并且分担负载压力.官方文档是这样说的:A single instance of Node.j ...

  8. strcasecmp在VS2010中提示未定义标识符

    分析: strcasecmp(*,*)是用来比较字符串,定义在string.h头文件中,但是在windows下即使添加string.h头文件,依然会报错. 解决: 添加 #if defined(_MS ...

  9. <转>详解DNS的常用记录(上):DNS系列之二

    详解DNS的常用记录(上) 在上篇博文中,我们介绍了DNS服务器的体系结构,从中我们了解到如果我们希望注册一个域名,那么必须经过顶级域名服务器或其下级的域名服务器为我们申请的域名进行委派,把解析权委派 ...

  10. Tkinter教程之Canvas篇(4)

    本文转载自:http://blog.csdn.net/jcodeer/article/details/1812091 '''Tkinter教程之Canvas篇(4)''''''22.绘制弧形'''#  ...