富文本
http://pan.baidu.com/s/1pjny8bl
把這裡下載下傳的檔案夾拖進自己的工程
引入頭檔案
#import "ohattributedlabel.h"
#import "ohparagraphstyle.h"
#import "ohtouchesgesturerecognizer.h"
引入這3個頭檔案
添加 coretext.framework
// 建立富文本string
nsmutableattributedstring* attrstr = \
[nsmutableattributedstring
attributedstringwithstring:\
@"還記得嗎,窗外那被月光染亮的海洋\
你還記得嗎,是愛讓彼此把夜點亮\
為何後來我們用沉默取代依賴 曾經朗朗星空,漸漸陰霾\
心碎離開,轉身回到最初荒涼裡等待 為了寂寞,是否找個人填心中空白\
我們變成了世上,最熟悉的陌生人 今後各自曲折,各自悲哀\
隻怪我們愛得那麼洶湧,愛得那麼深 于是夢醒了擱淺了沉默了揮手了\
卻回不了神,如果當初在交會時能忍住了 激動的靈魂"];
[attrstr settextcolor:[uicolor whitecolor]];
[attrstr settextcolor:[uicolor redcolor]
range:nsmakerange(9,4)];
[attrstr settextisunderlined:yes range:nsmakerange(9,
4)];
[attrstr settextcolor:[uicolor greencolor]
range:nsmakerange(125,30)];
// 設定樣式
ohparagraphstyle* paragraphstyle = [ohparagraphstyle
defaultparagraphstyle];
paragraphstyle.textalignment = kcttextalignmentleft;
paragraphstyle.linebreakmode =
kctlinebreakbywordwrapping;
paragraphstyle.firstlineheadindent = 0.f; // indentation for
first line
paragraphstyle.linespacing = 3.f; // increase space between
lines by 3 points
[attrstr setparagraphstyle:paragraphstyle];
// 初始化富文本label
ohattributedlabel *label = \
[[ohattributedlabel alloc]
initwithframe:cgrectmake(0, 0, 300, 200)];
label.attributedtext = attrstr;
label.center = self.view.center;
// 添加進主視圖
[self.view addsubview:label];
以下是遊賢代碼
http://www.cnblogs.com/youxianming/p/3656900.html這個是設定富文本字型的https://github.com/daktales/uifontwdcustomloader需要把這裡下載下傳的兩個檔案夾拖入工程
想用什麼字型就把字型從網上下載下傳下來記住一定要是ttf格式的檔案哦 拖進工程 然後引入頭檔案
然後擷取字型url 注冊字型 設定字型風格
效果如下
具體的demo請鑒桌面·備用·demo·fontstyle
相關的連結有http://www.cnblogs.com/youxianming/p/3656900.html感謝部落客的分享