iOS 文字屬性,ios文字屬性

來源:互聯網
上載者:User

iOS 文字屬性,ios文字屬性

- (void)drawInRect:(CGRect)rect withAttributes:(NSDictionary *)attrs

-(void)drawRect:(CGRect)rect{    self.backgroundColor=[UIColor whiteColor];    NSString *attrString =@hello word;        NSDictionary* attrs =@{NSFontAttributeName:[UIFont fontWithName:@AmericanTypewriter size:30]                           }; //在詞典中加入文本的字型 大小        [attrString drawInRect:CGRectMake(20,120,320,200)withAttributes:attrs];}
置字型顏色
  NSDictionary* attrs =@{NSFontAttributeName:[UIFont fontWithName:@AmericanTypewriter size:30],//文本的顏色 字型 大小                           NSForegroundColorAttributeName:[UIColor redColor]//文字顏色                           };
二,NSParagraphStyleAttributeName
段落格式
-(void)drawRect:(CGRect)rect{    NSString *attrString =@hello word;        NSMutableParagraphStyle *paragraph=[[NSMutableParagraphStyle alloc]init];    paragraph.alignment=NSTextAlignmentCenter;//置中        NSDictionary* attrs =@{NSFontAttributeName:[UIFont fontWithName:@AmericanTypewriter size:30],//文本的顏色 字型 大小                           NSForegroundColorAttributeName:[UIColor redColor],//文字顏色                           NSParagraphStyleAttributeName:paragraph,//段落格式                           };        [attrString drawInRect:CGRectMake(20,120,320,200)withAttributes:attrs];}
三,NSBackgroundColorAttributeName
背景顏色
NSDictionary* attrs =@{NSFontAttributeName:[UIFont fontWithName:@AmericanTypewriter size:30],//文本的顏色 字型 大小                           NSForegroundColorAttributeName:[UIColor redColor],//文字顏色                           NSParagraphStyleAttributeName:paragraph,//段落格式                           NSBackgroundColorAttributeName:[UIColor blueColor],//背景色                           };
四,NSStrokeColorAttributeName
設定描邊顏色,需要和NSStrokeWidthAttributeName 一起使用
 NSDictionary* attrs =@{NSFontAttributeName:[UIFont fontWithName:@AmericanTypewriter size:30],//文本的顏色 字型 大小                           NSForegroundColorAttributeName:[UIColor redColor],//文字顏色                           NSParagraphStyleAttributeName:paragraph,//段落格式                           //NSBackgroundColorAttributeName:[UIColor blueColor],//背景色                           NSStrokeWidthAttributeName:@3, //描邊寬度                           NSStrokeColorAttributeName:[UIColor greenColor],//設定 描邊顏色,和NSStrokeWidthAttributeName配合使用,設定了這個NSForegroundColorAttributeName就失效了                           };
五,NSStrikethroughStyleAttributeName
刪除線
 NSDictionary* attrs =@{NSFontAttributeName:[UIFont fontWithName:@AmericanTypewriter size:30],//文本的顏色 字型 大小                           NSForegroundColorAttributeName:[UIColor redColor],//文字顏色                           NSParagraphStyleAttributeName:paragraph,//段落格式//                           NSBackgroundColorAttributeName:[UIColor blueColor],//背景色                           NSStrokeWidthAttributeName:@3, //描邊寬度                           NSStrokeColorAttributeName:[UIColor greenColor],//設定 描邊顏色,和NSStrokeWidthAttributeName配合使用,設定了這個NSForegroundColorAttributeName就失效了                                                   NSStrikethroughStyleAttributeName:@1,//刪除線,數字代表線條寬度                           };
六,NSUnderlineStyleAttributeName
底線
NSDictionary* attrs =@{NSFontAttributeName:[UIFont fontWithName:@AmericanTypewriter size:30],//文本的顏色 字型 大小                           NSForegroundColorAttributeName:[UIColor redColor],//文字顏色                           NSParagraphStyleAttributeName:paragraph,//段落格式//                           NSBackgroundColorAttributeName:[UIColor blueColor],//背景色                           NSStrokeWidthAttributeName:@3, //描邊寬度                           NSStrokeColorAttributeName:[UIColor greenColor],//設定 描邊顏色,和NSStrokeWidthAttributeName配合使用,設定了這個NSForegroundColorAttributeName就失效了                        //                           NSStrikethroughStyleAttributeName:@1,//刪除線,數字代表線條寬度                           NSUnderlineStyleAttributeName:@(NSUnderlineStyleSingle),//底線,值為一個枚舉類型,大家可以分別試試                           };
七,NSShadowAttributeName
設定陰影,他的對象是一個NSShadow的對象
 NSDictionary* attrs =@{NSFontAttributeName:[UIFont fontWithName:@AmericanTypewriter size:30],//文本的顏色 字型 大小                           NSForegroundColorAttributeName:[UIColor redColor],//文字顏色                           NSParagraphStyleAttributeName:paragraph,//段落格式//                           NSBackgroundColorAttributeName:[UIColor blueColor],//背景色                           NSStrokeWidthAttributeName:@3, //描邊寬度                           NSStrokeColorAttributeName:[UIColor greenColor],//設定 描邊顏色,和NSStrokeWidthAttributeName配合使用,設定了這個NSForegroundColorAttributeName就失效了                        //                           NSStrikethroughStyleAttributeName:@1,//刪除線,數字代表線條寬度                           NSUnderlineStyleAttributeName:@(NSUnderlineStyleSingle),//底線,值為一個枚舉類型,大家可以分別試試                           NSShadowAttributeName:shadow,//設定陰影,複製為一個NSShadow 的對象                                                      };

NSShadow
  NSShadow *shadow=[[NSShadow alloc]init];    shadow.shadowBlurRadius=5;//陰影的模糊程度    shadow.shadowColor=[UIColor blueColor];//陰影顏色    shadow.shadowOffset=CGSizeMake(6, 6);//陰影相對原來的位移
八,NSObliquenessAttributeName
傾斜
  NSDictionary* attrs =@{NSFontAttributeName:[UIFont fontWithName:@AmericanTypewriter size:30],//文本的顏色 字型 大小                           NSForegroundColorAttributeName:[UIColor redColor],//文字顏色                           NSParagraphStyleAttributeName:paragraph,//段落格式//                           NSBackgroundColorAttributeName:[UIColor blueColor],//背景色                           NSStrokeWidthAttributeName:@3, //描邊寬度                           NSStrokeColorAttributeName:[UIColor greenColor],//設定 描邊顏色,和NSStrokeWidthAttributeName配合使用,設定了這個NSForegroundColorAttributeName就失效了                        //                           NSStrikethroughStyleAttributeName:@1,//刪除線,數字代表線條寬度                           NSUnderlineStyleAttributeName:@(NSUnderlineStyleSingle),//底線,值為一個枚舉類型,大家可以分別試試                           NSShadowAttributeName:shadow,//設定陰影,複製為一個NSShadow 的對象                           NSObliquenessAttributeName:@1//傾斜程度                           };


 



 



















































 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.