设置title样式
UINavgationBar提供了titleTextAttributes 属性来简单的设置其title样式,titleTextAttributes是一个NSDictionary类型,包含的固定的属性名称,可以用来设置title的样式,指定的属性keys
声明于NSString UIKit Additions Reference扩展中,包括:
NSString *constUITextAttributeFont,设置title的文字字体;
NSString*constUITextAttributeTextColor,设置title的文字颜色;
NSString*constUITextAttributeTextShadowColor,设置titlewz的阴影颜色;
NSString*constUITextAttributeTextShadowOffset,设置titlewz阴影的平移量 ;
如,设置title样式为:系统默认bold类型20号红色字体,阴影颜色为白色,右下偏移2像素
NSDictionary *navTitleArr =[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont boldSystemFontOfSize:20],UITextAttributeFont,
[UIColor redColor],UITextAttributeTextColor ,[NSValue valueWithCGSize:CGSizeMake(2.0,2.0)] , UITextAttributeTextShadowOffset,[UIColor whiteColor] ,UITextAttributeTextShadowColor ,nil];[navBar setTitleTextAttributes:navTitleArr];
segmentcontrol的颜色字体
/改变segment的字体大小和颜色
NSDictionary*dic = [NSDictionarydictionaryWithObjectsAndKeys:[UIColorblackColor],UITextAttributeTextColor,[UIFontfontWithName:@"AppleGothic"size:14],UITextAttributeFont,nil];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor],NSForegroundColorAttributeName, nil];
//设置各种状态的字体和颜色
[self.segmentedControlsetTitleTextAttributes:dicforState:UIControlStateNormal];
网友评论