UIAppearance
有时侯你并不想把导航条左侧按钮外观字体或背景全部用以下代码来更改
[plain]
UIBarButtonItem *rightItem = [YBarButtonItem barButtonWithStyle:YBarButtonStyleRoundedRectangle
Title:@"Save"
Action:@selector(saveButtonClicked)
Delegate:self];
self.navigationItem.leftBarButtonItem = rightItem;
这里就有个方法可以进行全局或局部的修改:
iOS5提供了一个比较强大的工具UIAppearance,可以轻松的统一你的界面,它提供如下两个方法:
+ (id)appearance
+ (id)appearanceWhenContainedIn:(Class <>)ContainerClass,...
第一个方法是统一全部改,比如你设置UINavBar的tintColor,你可以这样写:[[UINavigationBar appearance] setTintColor:myColor];
第二个方法是当出现在某个类的出现时候才会改变:例如:
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], [UIPopoverController class], nil] setTintColor:myPopoverNavBarColor];
1.修改背景:
[plain]
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:leftButton
forState:0
barMetrics:UIBarMetricsDefault];
2.修改字体,阴影,字体颜色
[plain]
NSDictionary* textAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
BAR_BUTTON_TITLE_TEXT_COLOR,UITextAttributeTextColor,
BAR_BUTTON_TITLE_FONT,UITextAttributeFont,
BAR_BUTTON_TITLE_SHADOW_COLOR,UITextAttributeTextShadowColor,
[NSValue valueWithCGSize:CGSizeMake(1, 1)],UITextAttributeTextShadowOffset,
nil];
[[UIBarButtonItem appearance] setTitleTextAttributes:textAttributes forState:0];
3,修改UIBarButtonItem中文字的位置:
[plain]
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(2, -1)
forBarMetrics:UIBarMetricsDefault];
转:http://www.2cto.com/kf/201301/186764.html