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. 【JSP】JSP向MySQL写入|读出中文数据——乱码问题

    注意第14行

  2. Android-AnimationDrawable(三)运行的几种方式

    项目开发用到了AnimationDrawable,调用start后没有运行,很纳闷.google搜了下.记录一下. 这个AnimationDrawable.start不能直接写在onClick,onS ...

  3. H264相关知识

    1.基本概念 I frame :帧内编码帧 又称intra picture,I 帧通常是每个 GOP(MPEG 所使用的一种视频压缩技术)的第一个帧,经过适度地压缩,做为随机访问的参考点,可以当成图象 ...

  4. ASP.NET MVC+Bootstrap个人博客之后台dataTable数据列表(五)

    jQuery  dataTables 插件是一个优秀的表格插件,是后台工程师的福音!它提供了针对数据表格的排序.浏览器分页.服务器分页.查询.格式化等功能.dataTables 官网也提供了大量的演示 ...

  5. git学习一

    一:Git是什么? Git是目前世界上最先进的分布式版本控制系统. 二:SVN与Git的最主要的区别? SVN是集中式版本控制系统,版本库是集中放在中央服务器的,而干活的时候,用的都是自己的电脑,所以 ...

  6. 如何清除win7开机密码

    一.电脑已经登录到系统,但是忘记了密1对于这种情况是最简单的,其实只需要将密码取消就可以了右键单击桌面上我的电脑,选择管理即可进入计算机管理界面2依次展开系统工具--本地用户和组--用户,在右侧选择要 ...

  7. 设置layoutControl1 中的 控件的 focus

    设置 layoutControl1 中的layoutControl EnableAutoTabOrder 为 false; this.layoutControl1.ActiveControl = th ...

  8. JQuery插件的学习

    此前一直想就关于Jquery插件的开发,做一个深入的学习,由于各种原因,当然主要是自己太懒了...今天就系统分析一下Jquery插件的开发(参考了http://www.xprogrammer.com/ ...

  9. 怎么对HTML 5的特性做检测?

    原译文地址:http://www.ido321.com/1116.html 原文:Detect HTML5 Features 译文:HTML5特性检测 译者:dwqs 随 着HTML 5的流行,现在H ...

  10. matlab特征值分解和奇异值分解

    特征值分解 函数 eig 格式 d = eig(A)         %求矩阵A的特征值d,以向量形式存放d. d = eig(A,B)       %A.B为方阵,求广义特征值d,以向量形式存放d. ...