[IOS]通過category來控制UIViewController的Navigation样式
程序员文章站
2022-05-30 22:22:10
...
新建Category类,拓展UIViewController:
例如想调navigation bar的回退键样式,那么在.m中:
@implementation UIViewController (BackNavigationBar) -(void)awakeFromNib{ [super awakeFromNib]; self.navigationItem.leftBarButtonItem = [self backButton]; NSLog(@"test test:%f",self.navigationItem.leftBarButtonItem.customView.frame.origin.x); } - (UIBarButtonItem *)backButton { UIBarButtonItem * item = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"ic_back" ] style:UIBarButtonItemStylePlain target:self action:@selector(backButtonPressed)]; return item; } -(void)backButtonPressed{ [self.navigationController popViewControllerAnimated:YES]; } @end
所有的UIViewController会自动继承了这些更改