iOS自己總結的超級詳細分解富文本大全(AttributedString),圖文混排很輕松
轉載于?http://blog.csdn/deft_mkjing/article/details/52141936
NSFontAttributeName???????????????設置字體大小和字體的類型?默認12Helvetica(Neue)
NSForegroundColorAttributeName????設置字體顏色,默認黑色?UIColor對象
NSBackgroundColorAttributeName????設置字體所在區域的背景顏色,默認為nil,透明色
NSLigatureAttributeName???????????設置連體屬性,NSNumber對象?默認0沒有連體
NSKernAttributeName???????????????設置字符間距,?NSNumber浮點型屬性?正數間距加大,負數間距縮小
NSStrikethroughStyleAttributeName?設置刪除線,NSNumber對象
NSStrikethroughColorAttributeName?設置刪除線顏色,UIColor對象,默認是黑色
NSUnderlineStyleAttributeName?????設置下劃線,NSNumber對象?NSUnderlineStyle枚舉值
NSUnderlineColorAttributeName?????設置下劃線顏色,UIColor對象,默認是黑色
NSStrokeWidthAttributeName????????設置筆畫寬度,NSNumber對象?正數中空?負數填充
NSStrokeColorAttributeName????????設置填充部分顏色,不是指字體顏色,UIColor對象
NSShadowAttributeName?????????????設置陰影屬性,取值為NSShadow對象
NSTextEffectAttributeName?????????設置文本特殊效果?NSString對象?只有圖版印刷效果可用
NSBaselineOffsetAttributeName?????設置基線偏移量,NSNumberfloat對象?正數向上偏移,負數向下偏移
NSObliquenessAttributeName????????設置字體傾斜度,NSNumberfloat對象,正數右傾斜,負數左傾斜
NSExpansionAttributeName??????????設置文本橫向拉伸屬性,NSNumberfloat對象,正數橫向拉伸文本,負數壓縮
NSWritingDirectionAttributeName???設置文字書寫方向,從左向右或者右向左
NSVerticalGlyphFormAttributeName??設置文本排版方向,NSNumber對象。0橫向排版,1豎向排版
NSLinkAttributeName???????????????設置文本超鏈接,點擊可以打開指定URL地址
NSAttachmentAttributeName?????????設置文本附件,取值為NSTextAttachment對象,一般為圖文混排
NSParagraphStyleAttributeName?????設置文本段落排版,為NSParagraphStyle對象
道來,每個屬性一行,分分鐘教大家簡單學習富文本
1.NSFontAttributeName
說明:該屬性用于改變一段文本的字體。如果不指定該屬性,則默認為12-point Helvetica(Neue)
2.NSForegroundColorAttributeName
說明:該屬性用于指定一段文本的字體顏色。如果不指定該屬性,則默認為黑色
3.NSBackgroundColorAttributeName
說明:設置文字背景顏色
NSString*string?=@"落霞與孤鶩齊飛,秋水共長天一色";
NSMutableAttributedString*mutableAttriteStr?=?[[NSMutableAttributedStringalloc]init];
NSAttributedString*attributeStr1=?[[NSAttributedStringalloc]initWithString:[stringsubstringWithRange:NSMakeRange(0,3)]attributes:@{NSFontAttributeName?:[UIFontfontWithName:@"futura"size:12],NSForegroundColorAttributeName?:?[UIColorredColor],NSBackgroundColorAttributeName?:?[UIColoryellowColor]}];
NSAttributedString*attributeStr4=?[[NSAttributedStringalloc]initWithString:[stringsubstringWithRange:NSMakeRange(3,4)]attributes:@{NSFontAttributeName?:[UIFontfontWithName:@"futura"size:22],NSForegroundColorAttributeName?:?[UIColorredColor],NSBackgroundColorAttributeName?:?[UIColoryellowColor]}];
NSAttributedString*attributeStr2=?[[NSAttributedStringalloc]initWithString:[stringsubstringWithRange:NSMakeRange(8,4)]attributes:@{NSFontAttributeName?:?[UIFontboldSystemFontOfSize:22],NSForegroundColorAttributeName?:?[UIColorblackColor],NSBackgroundColorAttributeName?:?[UIColorlightGrayColor]}];
NSAttributedString*attributeStr5=?[[NSAttributedStringalloc]initWithString:[stringsubstringWithRange:NSMakeRange(12,3)]attributes:@{NSFontAttributeName?:?[UIFontboldSystemFontOfSize:12],NSForegroundColorAttributeName?:?[UIColorblackColor],NSBackgroundColorAttributeName?:?[UIColorlightGrayColor]}];
NSAttributedString*attriteStr3=?[[NSAttributedStringalloc]initWithString:[stringsubstringWithRange:NSMakeRange(7,1)]attributes:@{NSBackgroundColorAttributeName?:?[UIColorgreenColor]}];
[mutableAttriteStrappendAttributedString:attributeStr1];
[mutableAttriteStrappendAttributedString:attributeStr4];
[mutableAttriteStrappendAttributedString:attriteStr3];
[mutableAttriteStrappendAttributedString:attributeStr2];
[mutableAttriteStrappendAttributedString:attributeStr5];
self.label1.attributedText=?mutableAttriteStr;
4.NSLigatureAttributeName
連體字符是指某些連在一起的字符,它們采用單個的圖元符號。0 表示沒有連體字符。1
表示使用默認的連體字符。2表示使用所有連體符號。默認值為 1(注意,iOS不支持值
為 2)
//?連體藝術字,不是每個都能連起的,f和l??f和i就可以,其他各位可以自己去試試
self.label2.attributedText=?[[NSAttributedStringalloc]initWithString:@"flush?and?fily"attributes:@{NSLigatureAttributeName?:?[NSNumbernumberWithInt:1],NSFontAttributeName?:?[UIFontfontWithName:@"futura"size:30]}];
NSMutableAttributedString*mutableAttributeStr2=?[[NSMutableAttributedStringalloc]init];
NSAttributedString*string6=?[[NSAttributedStringalloc]initWithString:@"ABCDE?"attributes:@{NSKernAttributeName?:?[NSNumbernumberWithInt:-3],NSForegroundColorAttributeName?:?[UIColorredColor]}];
NSAttributedString*string7=?[[NSAttributedStringalloc]initWithString:@"FGHIJ?"attributes:@{NSKernAttributeName?:?[NSNumbernumberWithInt:0],NSForegroundColorAttributeName?:?[UIColoryellowColor]}];
NSAttributedString*string8=?[[NSAttributedStringalloc]initWithString:@"KLMNO?"attributes:@{NSKernAttributeName?:?@(15),NSForegroundColorAttributeName?:?[UIColorblueColor]}];
[mutableAttributeStr2appendAttributedString:string6];
[mutableAttributeStr2appendAttributedString:string7];
[mutableAttributeStr2appendAttributedString:string8];
self.label3.attributedText=?mutableAttributeStr2;
5.NSKernAttributeName
字符間距正值間距加寬,負值間距變窄
[objc]view plaincopy
NSMutableAttributedString*mutableAttributeStr2=?[[NSMutableAttributedStringalloc]init];
NSAttributedString*string6=?[[NSAttributedStringalloc]initWithString:@"ABCDE?"attributes:@{NSKernAttributeName?:?[NSNumbernumberWithInt:-3],NSForegroundColorAttributeName?:?[UIColorredColor]}];
NSAttributedString*string7=?[[NSAttributedStringalloc]initWithString:@"FGHIJ?"attributes:@{NSKernAttributeName?:?[NSNumbernumberWithInt:0],NSForegroundColorAttributeName?:?[UIColoryellowColor]}];
NSAttributedString*string8=?[[NSAttributedStringalloc]initWithString:@"KLMNO?"attributes:@{NSKernAttributeName?:?@(15),NSForegroundColorAttributeName?:?[UIColorblueColor]}];
[mutableAttributeStr2appendAttributedString:string6];
[mutableAttributeStr2appendAttributedString:string7];
[mutableAttributeStr2appendAttributedString:string8];
self.label3.attributedText=?mutableAttributeStr2;
6.NSStrikethroughStyleAttributeName ?和 NSStrikethroughColorAttributeName
NSStrikethroughStyleAttributeName 設置刪除線,取值為 NSNumber 對象(整數),
NSStrikethroughColorAttributeName 設置刪除線顏色
枚舉常量 NSUnderlineStyle中的值:
NSUnderlineStyleNone? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? =0x00, ?不設置
NSUnderlineStyleSingle? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? =0x01, ? 設置單細刪除線
NSUnderlineStyleThickNS_ENUM_AVAILABLE(10_0,7_0) ? =0x02, 設置粗單刪除線
NSUnderlineStyleDoubleNS_ENUM_AVAILABLE(10_0,7_0) ? ? =0x09,雙細刪除線
[objc]view plaincopy
NSMutableAttributedString*mutableAttributeStr3=?[[NSMutableAttributedStringalloc]init];
NSAttributedString*string9=?[[NSAttributedStringalloc]initWithString:@"只要998??"attributes:@{NSStrikethroughStyleAttributeName?:?@(NSUnderlineStyleSingle),NSStrikethroughColorAttributeName?:?[UIColorredColor]}];
NSAttributedString*string10=?[[NSAttributedStringalloc]initWithString:@"真的998??"attributes:@{NSStrikethroughStyleAttributeName?:?@(NSUnderlineStyleThick),NSStrikethroughColorAttributeName?:?[UIColorblueColor]}];
NSAttributedString*string11=?[[NSAttributedStringalloc]initWithString:@"好吧9塊拿走"attributes:@{NSStrikethroughStyleAttributeName?:?@(NSUnderlineStyleDouble),NSStrikethroughColorAttributeName?:?[UIColoryellowColor]}];
[mutableAttributeStr3appendAttributedString:string9];
[mutableAttributeStr3appendAttributedString:string10];
[mutableAttributeStr3appendAttributedString:string11];
self.label4.attributedText=?mutableAttributeStr3;
7.NSUnderlineStyleAttributeName 和
NSUnderlineColorAttributeName
給文字加下劃線和更換下劃線顏色,屬性和上面的刪除線都是一樣用的
[objc]view plaincopy
NSMutableAttributedString*mutableAttributeStr4=?[[NSMutableAttributedStringalloc]init];
NSAttributedString*string12=?[[NSAttributedStringalloc]initWithString:@"只要888??"attributes:@{NSUnderlineStyleAttributeName?:?@(NSUnderlineStyleSingle),NSUnderlineColorAttributeName?:?[UIColorredColor]}];
NSAttributedString*string13=?[[NSAttributedStringalloc]initWithString:@"真的88??"attributes:@{NSUnderlineStyleAttributeName?:?@(NSUnderlineStyleThick),NSUnderlineColorAttributeName?:?[UIColorpurpleColor]}];
NSAttributedString*string14=?[[NSAttributedStringalloc]initWithString:@"好吧8塊拿走"attributes:@{NSUnderlineStyleAttributeName?:?@(NSUnderlineStyleDouble),NSUnderlineColorAttributeName?:?[UIColoryellowColor]}];
[mutableAttributeStr4appendAttributedString:string12];
[mutableAttributeStr4appendAttributedString:string13];
[mutableAttributeStr4appendAttributedString:string14];
self.label5.attributedText=?mutableAttributeStr4;
8.NSStrokeWidthAttributeName 和NSStrokeColorAttributeName
設置文字描邊顏色,需要和NSStrokeWidthAttributeName設置描邊寬度,這樣就能使文字空心.
NSStrokeWidthAttributeName 這個屬性所對應的值是一個 NSNumber 對象(小數)。該值改變筆畫寬度(相對于字體 size 的百分比),負值填充效果,正值中空效果,默認為 0,即不改變。正數只改變描邊寬度。負數同時改變文字的描邊和填充寬度。例如,對于常見的空心字,這個值通常為 3.0。
同時設置了空心的兩個屬性,并且 NSStrokeWidthAttributeName 屬性設置為整數,文字前景色就無效果了
[objc]view plaincopy
NSMutableAttributedString*mutableAttributeStr5=?[[NSMutableAttributedStringalloc]init];
//?如果這個stroke的width正數的時候,字體就中空了,那么前景色就設置無效了
NSAttributedString*string15=?[[NSAttributedStringalloc]initWithString:@"HELLO?"attributes:@{NSStrokeWidthAttributeName?:?@(5),NSStrokeColorAttributeName?:?[UIColoryellowColor],NSFontAttributeName?:?[UIFontboldSystemFontOfSize:30],NSForegroundColorAttributeName?:?[UIColorredColor]}];
NSAttributedString*string16=?[[NSAttributedStringalloc]initWithString:@"YUKD??"attributes:@{NSStrokeWidthAttributeName?:?@(0),NSStrokeColorAttributeName?:?[UIColorredColor],NSFontAttributeName?:?[UIFontboldSystemFontOfSize:30]}];
NSAttributedString*string17=?[[NSAttributedStringalloc]initWithString:@"GOOGLE"attributes:@{NSStrokeWidthAttributeName?:?@(-5),NSStrokeColorAttributeName?:?[UIColorgreenColor],NSFontAttributeName?:?[UIFontboldSystemFontOfSize:30],NSForegroundColorAttributeName?:?[UIColorlightGrayColor]}];
[mutableAttributeStr5appendAttributedString:string15];
[mutableAttributeStr5appendAttributedString:string16];
[mutableAttributeStr5appendAttributedString:string17];
self.label6.attributedText=?mutableAttributeStr5;
9.NSShadowAttributeName
設置文字陰影,取值為NSShadow對象
[objc]view plaincopy
//?設置陰影
NSShadow*shadow?=?[[NSShadowalloc]init];
shadow.shadowBlurRadius=5.0f;//?模糊度
shadow.shadowColor=?[UIColorblueColor];
shadow.shadowOffset=?CGSizeMake(1,5);
NSAttributedString*string20=?[[NSAttributedStringalloc]initWithString:@"HELLO_HALY_璟"attributes:@{NSFontAttributeName?:?[UIFontboldSystemFontOfSize:30],NSForegroundColorAttributeName?:?[UIColorredColor],NSShadowAttributeName?:?shadow}];
self.label7.attributedText=?string20;
10.NSTextEffectAttributeNam
NSTextEffectAttributeName //設置文本特殊效果,取值為NSString類型,目前只有一個可用效果 NSTextEffectLetterpressStyle(凸版印刷效果)
[objc]view plaincopy
//?文本印刷,我也不知道是什么鬼
//?設置陰影
NSAttributedString*string21=?[[NSAttributedStringalloc]initWithString:@"HELLO_HALY_璟"attributes:@{NSFontAttributeName?:?[UIFontboldSystemFontOfSize:30],NSForegroundColorAttributeName?:?[UIColorredColor],NSShadowAttributeName?:?shadow,NSTextEffectAttributeName?:?NSTextEffectLetterpressStyle}];
self.label8.attributedText=?string21;
11.NSBaselineOffsetAttributeName
文字基線偏移,想要達到以下圖片的效果,就要設置需要的文字偏移,正數上移,負數下
移
[objc]view plaincopy
//?設置文本的基線?負數向下??正數向上??0不變
UIFont*bigFont?=?[UIFontboldSystemFontOfSize:36];
UIFont*smallFont?=?[UIFontboldSystemFontOfSize:bigFont.pointSize/2];
CGFloat?capHeight?=?bigFont.pointSize-?smallFont.pointSize;
NSMutableAttributedString*attributeString6=?[[NSMutableAttributedStringalloc]init];
NSAttributedString*string22=?[[NSAttributedStringalloc]initWithString:@"¥"attributes:@{NSFontAttributeName?:?smallFont,NSForegroundColorAttributeName?:?[UIColorblackColor],NSBaselineOffsetAttributeName?:?@(0)}];
NSAttributedString*string23=?[[NSAttributedStringalloc]initWithString:@"9"attributes:@{NSFontAttributeName?:?bigFont,NSForegroundColorAttributeName?:?[UIColorblueColor],NSBaselineOffsetAttributeName?:?@(0)}];
NSAttributedString*string24=?[[NSAttributedStringalloc]initWithString:@".99"attributes:@{NSFontAttributeName?:?smallFont,NSForegroundColorAttributeName?:?[UIColorblackColor],NSBaselineOffsetAttributeName?:?@(0)}];
NSAttributedString*string28=?[[NSAttributedStringalloc]initWithString:@"????七夕大促銷????"attributes:@{NSFontAttributeName?:?[UIFontboldSystemFontOfSize:24],NSForegroundColorAttributeName?:?[UIColorblackColor],NSBaselineOffsetAttributeName?:?@(0),NSShadowAttributeName?:?shadow}];
NSAttributedString*string25=?[[NSAttributedStringalloc]initWithString:@"¥"attributes:@{NSFontAttributeName?:?smallFont,NSForegroundColorAttributeName?:?[UIColorblackColor],NSBaselineOffsetAttributeName?:?@(capHeight?-5)}];
NSAttributedString*string26=?[[NSAttributedStringalloc]initWithString:@"0"attributes:@{NSFontAttributeName?:?bigFont,NSForegroundColorAttributeName?:?[UIColorredColor],NSBaselineOffsetAttributeName?:?@(0)}];
NSAttributedString*string27=?[[NSAttributedStringalloc]initWithString:@".09"attributes:@{NSFontAttributeName?:?smallFont,NSForegroundColorAttributeName?:?[UIColorblackColor],NSBaselineOffsetAttributeName?:?@(capHeight?-5)}];
[attributeString6appendAttributedString:string22];
[attributeString6appendAttributedString:string23];
[attributeString6appendAttributedString:string24];
[attributeString6appendAttributedString:string28];
[attributeString6appendAttributedString:string25];
[attributeString6appendAttributedString:string26];
[attributeString6appendAttributedString:string27];
self.label9.attributedText=?attributeString6;
NSMutableAttributedString*attributeString7=?[[NSMutableAttributedStringalloc]init];
NSAttributedString*string29=?[[NSAttributedStringalloc]initWithString:@"Hello??"attributes:@{NSFontAttributeName?:?[UIFontboldSystemFontOfSize:40],NSForegroundColorAttributeName?:?[UIColorblackColor],NSBaselineOffsetAttributeName?:?@(0)}];
NSAttributedString*string30=?[[NSAttributedStringalloc]initWithString:@"??World????"attributes:@{NSFontAttributeName?:?[UIFontboldSystemFontOfSize:20],NSForegroundColorAttributeName?:?[UIColorblackColor],NSBaselineOffsetAttributeName?:?@(0)}];
NSAttributedString*string31=?[[NSAttributedStringalloc]initWithString:@"Hello??"attributes:@{NSFontAttributeName?:?[UIFontboldSystemFontOfSize:40],NSForegroundColorAttributeName?:?[UIColorblackColor],NSBaselineOffsetAttributeName?:?@(0)}];
NSAttributedString*string32=?[[NSAttributedStringalloc]initWithString:@"??World"attributes:@{NSFontAttributeName?:?[UIFontboldSystemFontOfSize:20],NSForegroundColorAttributeName?:?[UIColorblackColor],NSBaselineOffsetAttributeName?:?@(6)}];
[attributeString7appendAttributedString:string29];
[attributeString7appendAttributedString:string30];
[attributeString7appendAttributedString:string31];
[attributeString7appendAttributedString:string32];
self.label10.attributedText=?attributeString7;
12.NSObliquenessAttributeName
NSObliquenessAttributeName 設置字體傾斜度,取值為 NSNumber(float),正值右傾,負值左傾
13.NSExpansionAttributeName
NSExpansionAttributeName 設置字體的橫向拉伸,取值為NSNumber (float),正值拉伸 ,負值壓縮
14.NSVerticalGlyphFormAttributeName
NSVerticalGlyphFormAttributeName 設置文字排版方向,取值為NSNumber對象(整數),0表示橫排文本,1表示豎排文本 在ios中只支持0
[objc]view plaincopy
//????說明:NSVerticalGlyphFormAttributeName?設置文字排版方向,取值為NSNumber對象(整數),0表示橫排文本,1表示豎排文本?在iOS中只支持0
//說明:NSObliquenessAttributeName?設置字體傾斜度,取值為?NSNumber(float),正值右傾,負值左傾
//????NSExpansionAttributeName
//????說明:NSExpansionAttributeName?設置字體的橫向拉伸,取值為NSNumber?(float),正值拉伸?,負值壓縮
NSMutableAttributedString*mutableAttriteStr?=?[[NSMutableAttributedStringalloc]init];
NSAttributedString*attributeStr1=?[[NSAttributedStringalloc]initWithString:@"HeHe_XiXi_mm"attributes:@{NSFontAttributeName?:[UIFontboldSystemFontOfSize:30],NSForegroundColorAttributeName?:?[UIColorredColor],NSShadowAttributeName?:?shadow,NSObliquenessAttributeName?:?@(1),NSExpansionAttributeName?:?@(1),NSVerticalGlyphFormAttributeName?:?@(1)}];
[mutableAttriteStrappendAttributedString:attributeStr1];
self.label1.attributedText=?mutableAttriteStr;
15.NSWritingDirectionAttributeName
文字書寫方向取值為以下組合為例 ?他是一個數組包含NSNumber 一般書寫就是L ---R
那么我們多個需求也就是從R --- L
The values of theNSNumberobjects should be0,1,2, or3, forLRE,RLE,LRO, orRLOrespectively, and combinations ofleftToRightandrightToLeftwithNSTextWritingDirectionEmbeddingorNSTextWritingDirectionOverride
[objc]view plaincopy
//?文字書寫方向
//????The?values?of?the?NSNumber?objects?should?be?0,?1,?2,?or?3,?for?LRE,?RLE,?LRO,?or?RLO?respectively,?and?combinations?of?leftToRight?and?rightToLeft?with?NSTextWritingDirectionEmbedding?or?NSTextWritingDirectionOverride,?as?shown?in?Table?1.
//????NSWritingDirectionLeftToRight?|?NSTextWritingDirectionEmbedding
//????NSWritingDirectionRightToLeft?|?NSTextWritingDirectionEmbedding
//????NSWritingDirectionLeftToRight?|?NSTextWritingDirectionOverride
//????NSWritingDirectionRightToLeft?|?NSTextWritingDirectionOverride
NSMutableAttributedString*attributuStr2=?[[NSMutableAttributedStringalloc]init];
NSAttributedString*string1=?[[NSAttributedStringalloc]initWithString:@"一切皆有可能"attributes:@{NSFontAttributeName?:?[UIFontboldSystemFontOfSize:24],NSForegroundColorAttributeName?:?[UIColorredColor],NSWritingDirectionAttributeName?:?@[@(3)]}];
[attributuStr2appendAttributedString:string1];
self.label.attributedText=?attributuStr2;
16.NSLinkAttributeName
這貨有點奇葩,所以很多人用第三方例如YYLabel來做,這東西不能在UILabel和UITextField使用,只能用UITextView來進行,實現他的代理,在代理方法里面進行URL跳轉
- (BOOL)textView:(UITextView*)textView shouldInteractWithURL:(NSURL*)URL inRange:(NSRange)characterRange
該方法返回YES就能打開URL,NO不做任何事情
注:
1.一定要實現UITextView的代理才能進行URL跳轉
2.textView的editable屬性修改為NO,在編輯時不可點擊
[objc]view plaincopy
//????把?NSLinkAttributeName?屬性單獨列出來,是因為在?UILabel?和?UITextField?中是無法使用該屬性的。更準確點說是在UILabel?和?UITextField?中無法實現點擊鏈接啟動瀏覽器打開一個URL地址,因為在此過程中用到了一個代理函數。只能用在?UITextView?中
self.textView.delegate=self;
self.textView.scrollEnabled=NO;
self.textView.editable=NO;
self.textView.textContainer.lineFragmentPadding=0;
self.textView.textContainerInset=?UIEdgeInsetsMake(0,0,0,0);
NSString*str?=@"??跳轉到宓珂璟的博客";
NSMutableAttributedString*attrStr?=?[[NSMutableAttributedStringalloc]initWithString:str];
[attrStraddAttribute:NSLinkAttributeNamevalue:[NSURLURLWithString:@"http://blog.csdn.net/deft_mkjing"]range:[strrangeOfString:@"宓珂璟的博客"]];
[attrStraddAttribute:NSFontAttributeNamevalue:[UIFontboldSystemFontOfSize:30]range:NSMakeRange(0,?str.length)];
self.textView.attributedText=?attrStr;
17.NSTextAttachment
設置文本附件,取值為NSTextAttachment對象 常用于圖文混排
[objc]view plaincopy
NSString*words?=@"天才";
NSMutableAttributedString*strAtt?=?[[NSMutableAttributedStringalloc]initWithString:wordsattributes:@{NSFontAttributeName?:?[UIFontboldSystemFontOfSize:25]}];
NSTextAttachment*attatch?=?[[NSTextAttachmentalloc]initWithData:nilofType:nil];
attatch.bounds=?CGRectMake(0,0,40,30);
attatch.image=?[UIImageimageNamed:@"$DCZ2WLN9RWI6JF(Q`P_(NH.jpg"];
NSTextAttachment*attatch1=?[[NSTextAttachmentalloc]initWithData:nilofType:nil];
attatch1.bounds=?CGRectMake(0,0,50,30);
attatch1.image=?[UIImageimageNamed:@"%5T@J(4WKWSOX2~~PY0{4M0.jpg"];
NSAttributedString*string8=?[NSAttributedStringattributedStringWithAttachment:attatch];
NSAttributedString*string9=?[NSAttributedStringattributedStringWithAttachment:attatch1];
[strAttinsertAttributedString:string8atIndex:1];
[strAttinsertAttributedString:string9atIndex:0];
self.label3.attributedText=?strAtt;
基本的就介紹到這里了,上面那些已經足夠用了,而且可以任意組合出想要的圖文混排,
如果遇到特殊的需求或者不能滿足的,那么就需要各位去試試往上的第三方富文本了
給個好用的大家可以試試點擊打開鏈接
本次Demo地址:Demo傳送門
Demo里面貌似沒有注釋掉多余的屬性列表,大家要看的自行注釋一下
謝謝大家閱讀,記錄的同時希望能幫到大家?。?!
頂
?圖文混排
?實現圖文混排ListView展示 ---- Android版
?iOS圖文混排(需要在文本或者字符串中某些特定位置添加文本框)
?小胖說事13--------NSTextAttachment富文本控件實現圖文混排
猜你在找
IT(6)
ios(216)
人工智能(1)
服務器(7)
android 安全(9)
android 測試工具(12)
android崩潰(4)
c語言(1)
產品(15)
外貿(1)
IOS異常(2)
PS(1)
基礎算法+基礎知識總結(13)
設計模式(1)
Job(19)
文章存檔
2017年06月(2)
2017年05月(4)
2017年04月(9)
2017年03月(16)
2017年02月(11)
展開
閱讀排行
RecyclerView setHasFixedSize(true); 的作用(14385)
Android自定義View進階 - 貝塞爾曲線(4479)
把Android手機變成遠程監控攝像頭(3394)
GLIDE 的 一些用法(2971)
51個賺錢最好的方法(史上最全攻略)(2919)
TabLayout:另一種Tab的實現方式(2890)
eclipse轉android studio常遇到的問題(2011)
安卓7.1 新特性Shortcut(1795)
ViewCompat.animate 動畫實現方式(1780)
通過代碼 新增 和 “修改”NSLayoutConstraint(1625)
評論排行
Android 基于google Zxing實現二維碼、條形碼掃描,仿微信二維碼掃描效果(1)
Android性能優化 view.setLayerType(View.LAYER_TYPE_NONE, null); 來優化Property動畫(1)
drawLine DashPathEffect繪制虛線變成了實線(1)
Android 向右滑動銷毀(finish)Activity, 隨著手勢的滑動而滑動的效果(1)
最新評論
Android NDK——使用Android Studio引用so庫,jar包及module并使用JNI的正確姿勢
qq_38354031: 我來頂一個
孫華強: CSDN博友你好,我是孫華強,現將此篇博文收錄進“Android知識庫”。CSDN現在在做CSDN博...
Android性能優化 view.setLayerType(View.LAYER_TYPE_NONE, null); 來優化Property動畫
Boiling_Cola: 可以轉嗎?
renzhengjigou: 仔細看了一遍,收獲很大。
renzhengjigou: 仔細看了一遍,收獲很大。
twoOrEleven: 但是SparseArray里有沒有能替代hashMap中的containsKey()的Api呢?
qq_29964245: PC服務器端,改怎么弄博主
王虹蕓: CSDN的博客可見性可以設置嗎?
Burgessb: demo在哪