欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

[IOS]通過category來控制UIViewController的Navigation样式

程序员文章站 2022-03-26 18:35:42
...

新建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会自动继承了这些更改

相关标签: Navigation Bar