设置导航条左侧按钮(外观字体或背景)
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.修改背景:
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:leftButton
forState:0
barMetrics:UIBarMetricsDefault];
2.修改字体,阴影,字体颜色
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中文字的位置:
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(2, -1)
forBarMetrics:UIBarMetricsDefault];