有時侯你並不想把導航條左側按鈕外觀字體或背景所有用如下代碼來更改app
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]; (如今的版本都改爲了NSTextAttribute.......了)
[[UIBarButtonItem appearance] setTitleTextAttributes:textAttributes forState:0];
3,修改UIBarButtonItem中文字的位置:
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(2, -1) forBarMetrics:UIBarMetricsDefault];