---
title: "[ios] iOS 富文本类库RTLabel"
author: "119568242"
date: "2014-06-30T16:09:04Z"
tags: []
categories: ["移动开发"]
slug: "ios-ios-rtlabel"
draft: false
lastmod: "2014-06-30T16:09:04Z"
id: 2086858
url: "https://poolo.iteye.com/blog/2086858"
---

转自：[http://blog.csdn.net/duxinfeng2010](http://blog.csdn.net/duxinfeng2010)

 

本节关于RTLable基本介绍，原文来自 [https://github.com/honcheng/RTLabel](https://github.com/honcheng/RTLabel)

 

# []()RTLabel

基于富文本的格式，适用于iOS，类似HTML的标记。

![](http://img.blog.csdn.net/20130601172712820)

RTLabel 基于UILabel类的拓展,能够支持Html标记的富文本显示，它是基于Core Text,因此也支持Core Text上的一些东西。

 

# []()特点

##### []()

- 粗体和斜体
- 颜色和大小
- 下划线
- 缩进
- 字距
- 行距
- 超链接

# []()

# []()用法

1）将RTLabel.h 和 RTLabel.m 拖拽道你的工程中，导入Core Text.framework。添加头文件

**\[cpp]** [view plain](http://blog.csdn.net/duxinfeng2010/article/details/9004749 "view plain")[copy](http://blog.csdn.net/duxinfeng2010/article/details/9004749 "copy")

 

1. #import "RTLabel.h"

2)创建一个RTLabel

**\[cpp]** [view plain](http://blog.csdn.net/duxinfeng2010/article/details/9004749 "view plain")[copy](http://blog.csdn.net/duxinfeng2010/article/details/9004749 "copy")

 

1. NSString \*sample\_text = @"&lt;b&gt;bold&lt;/b&gt;,&lt;i&gt;italic&lt;/i&gt; and &lt;u&gt;underlined&lt;/u&gt; text, and &lt;font face='HelveticaNeue-CondensedBold' size=20 color='#CCFF00'&gt;text with custom font and color&lt;/font&gt;";
2. RTLabel \*label = \[\[RTLabel alloc] initWithFrame:...];
3. \[self addSubview:label];
4. \[label setText:sample\_text];

3)支持以下标签

**\[html]** [view plain](http://blog.csdn.net/duxinfeng2010/article/details/9004749 "view plain")[copy](http://blog.csdn.net/duxinfeng2010/article/details/9004749 "copy")

 

01. &lt;b&gt;Bold&lt;/b&gt;
02. &lt;i&gt;Italic&lt;/i&gt;
03. &lt;bi&gt;Bold & Italic&lt;/bi&gt;
04. &lt;u&gt;underline&lt;/u&gt;, &lt;u color=red&gt;underline with color&lt;/u&gt;
05. &lt;a href='http://..'&gt;link&lt;/a&gt;
06. &lt;uu&gt;double underline&lt;/uu&gt; , &lt;uu color='#ccff00'&gt;double underline with color&lt;/uu&gt;
07. &lt;font face='HelveticaNeue-CondensedBold' size=20 color='#CCFF00'&gt;custom font&lt;/font&gt;
08. &lt;font face='HelveticaNeue-CondensedBold' size=20 color='#CCFF00' stroke=1&gt;custom font with strokes&lt;/font&gt;
09. &lt;font face='HelveticaNeue-CondensedBold' size=20 color='#CCFF00' kern=35&gt;custom font with kerning&lt;/font&gt;
10. &lt;p align=justify&gt;alignment&lt;/p&gt;
11. &lt;p indent=20&gt;indentation&lt;/p&gt;

# []()最低要求

- ARC -RTLabel使用了ARC,如果你的工程没有使用ARC,在编译时 compiler flag 上 添加 '-fobjc-arc'(如下图显示)
- XCode 4.4 或以上新版本。

 

![](http://img.blog.csdn.net/20130601180121340)