ITeye博客

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

繁星水 · 2019-12-02 15:36 · IOS · 移动开发 · Navigation Bar · Markdown

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

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。