ITeye博客

[转]How to use NSAttributedString in iOS 6

re_reference · 2012-12-25 16:09 · iphone · ipad · ipod touch · 移动开发 · Markdown

本文转自:http://soulwithmobiletechnology.blogspot.com/2012/07/how-to-use-nsattributedstring-in-ios-6.html,版权归作者所有。


infoString=@"This is an example of Attributed String";

NSMutableAttributedString *attString=[[nsmutableattributedstring alloc] initWithString:infoString];
NSInteger _stringLength=[infostring length];

UIColor *_black=[uicolor blackcolor];
UIFont *font=[uifont fontwithname:@"helvetica-bold" size:30.0f];
[attstring addattribute:nsfontattributename value:font range:nsmakerange(0, _stringlength)];
[attstring addattribute:nsforegroundcolorattributename value:_black range:nsmakerange(0, _stringlength)];


UIColor *_red=[uicolor redcolor];
UIFont *font=[uifont fontwithname:@"helvetica-bold" size:72.0f];
[attstring addattribute:nsfontattributename value:font range:nsmakerange(0, _stringlength)];
[attstring addattribute:nsstrokecolorattributename value:_red range:nsmakerange(0, _stringlength)];
[attstring addattribute:nsstrokewidthattributename value:[nsnumber numberwithfloat:3.0] range:NSMakeRange(0, _stringLength)];


UIColor *_red=[uicolor redcolor];
UIFont *font=[uifont fontwithname:@"helvetica-bold" size:72.0f];
[attstring addattribute:nsfontattributename value:font range:nsmakerange(0, _stringlength)];
[attstring addattribute:nsstrokecolorattributename value:_red range:nsmakerange(0, _stringlength)];
[attstring addattribute:nsstrokewidthattributename value:[nsnumber numberwithfloat:-3.0] range:NSMakeRange(0, _stringLength)];


UIColor *_red=[uicolor redcolor];
UIColor *_green=[uicolor greencolor];
UIFont *font=[uifont fontwithname:@"helvetica-bold" size:72.0f];
[attstring addattribute:nsfontattributename value:font range:nsmakerange(0, _stringlength)];
[attstring addattribute:nsforegroundcolorattributename value:_green range:nsmakerange(0, _stringlength)];
[attstring addattribute:nsstrokecolorattributename value:_red range:nsmakerange(0, _stringlength)];
[attstring addattribute:nsstrokewidthattributename value:[nsnumber numberwithfloat:-3.0] range:NSMakeRange(0, _stringLength)];


UIColor *_green=[uicolor greencolor];
UIFont *font=[uifont fontwithname:@"helvetica-bold" size:72.0f];

NSShadow *shadowDic=[[nsshadow alloc] init];
[shadowdic setshadowblurradius:5.0];
[shadowdic setshadowcolor:[uicolor graycolor]];
[shadowdic setshadowoffset:cgsizemake(0, 3)];
              
[attstring addattribute:nsfontattributename value:font range:nsmakerange(0, _stringlength)];
[attstring addattribute:nsforegroundcolorattributename value:_green range:nsmakerange(0, _stringlength)];
[attstring addattribute:nsshadowattributename value:shadowdic range:nsmakerange(0, _stringlength)];


UIColor *_red=[uicolor redcolor];
UIFont *font=[uifont fontwithname:@"helvetica-bold" size:72.0f];
[attstring addattribute:nsfontattributename value:font range:nsmakerange(0, _stringlength)];
  [attstring addattribute:nsforegroundcolorattributename value:_red range:nsmakerange(0, _stringlength)];              
  [attstring addattribute:nskernattributename value:[nsnumber numberwithint:5] range:NSMak


UIColor *_red=[uicolor redcolor];
UIFont *font=[uifont fontwithname:@"helvetica-bold" size:30.0f];
[attstring addattribute:nsfontattributename value:font range:nsmakerange(0, _stringlength)];
[attstring addattribute:nsforegroundcolorattributename value:_red range:nsmakerange(0, _stringlength)];
[attstring addattribute:nsunderlinestyleattributename value:[nsnumber numberwithint:2] range:NSMakeRange(0, _stringLength)];


UIColor *_blue=[uicolor bluecolor];
UIColor *_blueL=[uicolor colorwithred:0 green:0 blue:0.5 alpha:0.7];
UIFont *font=[uifont fontwithname:@"helvetica-bold" size:30.0f];
                
[attstring addattribute:nsfontattributename value:font range:nsmakerange(0, _stringlength)];
[attstring addattribute:nsforegroundcolorattributename value:_blue range:nsmakerange(0, _stringlength)];
[attstring addattribute:nsbackgroundcolorattributename value:_bluel range:nsmakerange(0, 20)];

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。