drawInRect:withAttributes用法

iOS--drawInRect:withFont等方法在iOS7.0後背棄用,代替方法drawInRect:withAttributes用法(轉載)


1.NSKernAttributeName:@10 調整字句 kerning 字句調整

2.NSFontAttributeName : [UIFont systemFontOfSize:fontSize] 設置字體

3.NSForegroundColorAttributeName :[UIColor redColor] 設置文字顏色

4.NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
   paragraph.alignment = NSTextAlignmentCenter;
   NSParagraphStyleAttributeName:paragraph 設置段落樣式

5.NSBackgroundColorAttributeName:[UIColor blackColor] 設置背景顏色

6.NSStrokeWidthAttributeName:@3 設置文字描邊顏色
需要和NSStrokeWidthAttributeName設置描邊寬度,這樣就能使文字空心.
NSStrokeColorAttributeName:[UIColor greenColor]
NSStrokeWidthAttributeName這個屬性所對應的值是一個 NSNumber 對象(小數)。
該值改變描邊寬度(相對於字體size 的百分比)。默認爲 0,即不改變。
正數只改變描邊寬度。負數同時改變文字的描邊和填充寬度。
例如,對於常見的空心字,這個值通常爲3.0。
同時設置了空心的兩個屬性,並且NSStrokeWidthAttributeName屬性設置爲整數,文字前景色
NSForegroundColorAttributeName就無效果了。

7.NSStrikethroughStyleAttributeName:@3 添加刪除線,數字代表線條寬度

8.NSUnderlineStyleAttributeName:@(NSUnderlineStyleSingle) 添加下劃線,枚舉裏面有多種樣式。

   NSUnderlineColorAttributeName:[UIColor blueColor] 下劃線顏色


9.

NSShadow *shadow = [[NSShadow alloc] init];

    shadow.shadowColor = [UIColor grayColor];

    shadow.shadowBlurRadius = 2;

    shadow.shadowOffset = CGSizeMake(2, 4);

NSShadowAttributeName:shadow 設置陰影
NSVerticalGlyphFormAttributeName:@0  該屬性所對應的值是一個 NSNumber 對象(整數)。
				     0 表示橫排文本。1 表示豎排文本。
				     在 iOS 中,總是使用橫排文本,0 以外的值都未定義。
NSObliquenessAttributeName:@1 設置字體傾斜
NSExpansionAttributeName:@1 設置文本扁平化






發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章