drawInRect:withFont (ios7之前)
舉個??:
[self.high[0] drawInRect:CGRectMake(40,45, 20, 10) withFont:[UIFont boldSystemFontOfSize:10]];
drawInRect:withAttributes
舉個??:
UIColor *whiteColor = [UIColor whiteColor];
UIFont *font = [UIFont boldSystemFontOfSize:10];
[self.high[0] drawInRect:CGRectMake(40,45, 20, 10) withAttributes:@{NSFontAttributeName:font,NSForegroundColorAttributeName:whiteColor}];
withAttributes:參數(shù)是屬性字典含潘,該字典的key在NSAttributedString.h中獲得遏弱。
UIKIT_EXTERN NSString *const NSFontAttributeName NS_AVAILABLE_IOS(6_0); // UIFont, default Helvetica(Neue) 12
UIKIT_EXTERN NSString *const NSForegroundColorAttributeName NS_AVAILABLE_IOS(6_0); // UIColor, default blackColor
key是NSFontAttributeName漱逸、NSForegroundColorAttributeName游沿,value是UIFont對象和UIColor對象,使用的時候?qū)ey袋坑、value添加到屬性字典里即可枣宫。
其它地方使用withAttributes:方法相同也颤。
NSAttributedString.h
字符屬性
字符屬性可以應(yīng)用于 attributed string 的文本中郁轻。
NSString *const NSFontAttributeName;(字體)
NSString *const NSParagraphStyleAttributeName;(段落)
NSString *const NSForegroundColorAttributeName;(字體顏色)
NSString *const NSBackgroundColorAttributeName;(字體背景色)
NSString *const NSLigatureAttributeName;(連字符)
NSString *const NSKernAttributeName;(字間距)
NSString *const NSStrikethroughStyleAttributeName;(刪除線)
NSString *const NSUnderlineStyleAttributeName;(下劃線)
NSString *const NSStrokeColorAttributeName;(邊線顏色)
NSString *const NSStrokeWidthAttributeName;(邊線寬度)
NSString *const NSShadowAttributeName;(陰影)(橫豎排版)
NSString *const NSVerticalGlyphFormAttributeName;
常量
1> NSFontAttributeName(字體)
該屬性所對應(yīng)的值是一個 UIFont 對象好唯。該屬性用于改變一段文本的字體。如果不指定該屬性渠啊,則默認(rèn)為12-point Helvetica(Neue)替蛉。
2> NSParagraphStyleAttributeName(段落)
該屬性所對應(yīng)的值是一個 NSParagraphStyle 對象躲查。該屬性在一段文本上應(yīng)用多個屬性译柏。如果不指定該屬性,則默認(rèn)為 NSParagraphStyle 的defaultParagraphStyle 方法返回的默認(rèn)段落屬性典唇。
3> NSForegroundColorAttributeName(字體顏色)
該屬性所對應(yīng)的值是一個 UIColor 對象。該屬性用于指定一段文本的字體顏色恨胚。如果不指定該屬性炎咖,則默認(rèn)為黑色乘盼。
4> NSBackgroundColorAttributeName(字體背景色)
該屬性所對應(yīng)的值是一個 UIColor 對象。該屬性用于指定一段文本的背景顏色级野。如果不指定該屬性粹胯,則默認(rèn)無背景色矛双。
5> NSLigatureAttributeName(連字符)
該屬性所對應(yīng)的值是一個 NSNumber 對象(整數(shù))。連體字符是指某些連在一起的字符懒闷,它們采用單個的圖元符號愤估。0 表示沒有連體字符速址。1 表示使用默認(rèn)的連體字符玩焰。2表示使用所有連體符號。默認(rèn)值為 1(注意芍锚,iOS 不支持值為 2)昔园。
6> NSKernAttributeName(字間距)
該屬性所對應(yīng)的值是一個 NSNumber 對象(整數(shù))。字母緊排指定了用于調(diào)整字距的像素點數(shù)并炮。字母緊排的效果依賴于字體默刚。值為 0 表示不使用字母緊排。默認(rèn)值為0逃魄。
7> NSStrikethroughStyleAttributeName(刪除線)
該屬性所對應(yīng)的值是一個 NSNumber 對象(整數(shù))荤西。該值指定是否在文字上加上刪除線,該值參考“Underline Style Attributes”。默認(rèn)值是NSUnderlineStyleNone邪锌。
8> NSUnderlineStyleAttributeName(下劃線)
該屬性所對應(yīng)的值是一個 NSNumber 對象(整數(shù))勉躺。該值指定是否在文字上加上下劃線,該值參考“Underline Style Attributes”觅丰。默認(rèn)值是NSUnderlineStyleNone饵溅。
9> NSStrokeColorAttributeName(邊線顏色)
該屬性所對應(yīng)的值是一個 UIColor 對象。如果該屬性不指定(默認(rèn)),則等同于 NSForegroundColorAttributeName放典。否則,指定為刪除線或下劃線顏色拱层。更多細(xì)節(jié)見“Drawing attributedstrings that are both filled and stroked”。
10> NSStrokeWidthAttributeName(邊線寬度)
該屬性所對應(yīng)的值是一個 NSNumber 對象(小數(shù))。該值改變描邊寬度(相對于字體size 的百分比)桃笙。默認(rèn)為 0,即不改變脚祟。正數(shù)只改變描邊寬度邮丰。負(fù)數(shù)同時改變文字的描邊和填充寬度剪廉。例如,對于常見的空心字捞蚂,這個值通常為3.0。
11> NSShadowAttributeName(陰影)
該屬性所對應(yīng)的值是一個 NSShadow 對象。默認(rèn)為 nil解寝。
12> NSVerticalGlyphFormAttributeName(橫豎排版)
該屬性所對應(yīng)的值是一個 NSNumber 對象(整數(shù))。0 表示橫排文本。1 表示豎排文本抑片。在 iOS 中,總是使用橫排文本植捎,0 以外的值都未定義。