navigationBar和statusBar
我們都知道一個navigaitonController中的navigationBar是統一的,同時對于statusBar的樣式也是,如果需要設置統一風格,最好在navigationController中統一設置.
#import "WBFaceBasicNavigationController.h"
@interface WBFaceBasicNavigationController ()
@end
@implementation WBFaceBasicNavigationController
+(void)initialize{
// 在這里設置所有關于navigationBar的統一的屬性
UINavigationBar * navigationBar = [UINavigationBar appearanceWhenContainedInInstancesOfClasses:@[[self class]]];
[navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
navigationBar.translucent = YES;
[navigationBar setShadowImage:[UIImage new]];
[navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor], NSFontAttributeName: [UIFont systemFontOfSize:17]}];
navigationBar.barTintColor = [UIColor whiteColor];
}
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
viewController.navigationItem.hidesBackButton = YES;
[super pushViewController:viewController animated:animated];
}
/**
* 默認返回值為nil。
* 當我們調用setNeedsStatusBarAppearanceUpdate時,系統會調用application.window的rootViewController的preferredStatusBarStyle
* 方法
* 我們的程序里一般都是用UINavigationController做root,如果是這種情況,那我們自己的UIViewController里的preferredStatusBarStyle根本不會被調用
* 這個時候不要調用我自己(就是UINavigationController)的preferredStatusBarStyle方法,而是去調用navigationController.topViewController的preferredStatusBarStyle方法
*
* @return stack最上層的vc,我們知道navigation是以stack的形式跳轉的
*/
- (UIViewController *)childViewControllerForStatusBarStyle {
return self.topViewController;
}
@end
leftBarbuttonItem和rightBarbuttonItem
+(instancetype)itemWithImage:(NSString *)image selectedImage:(NSString *)selectedImage target:(id)target action:(SEL)action{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:selectedImage] forState:UIControlStateSelected];
button.bounds = CGRectMake(0, 0, 30, 30);
[button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
return [[self alloc] initWithCustomView:button];
}
@end
self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithImage:@"backbutton.png" selectedImage:@"backbutton.png" target:self action:@selector(faceVerifyComeBack)];