标签:
怎么样可以一次性把导航控制器中的返回键全都自定义。
思路:
我们可以在push的时候来设置这个自定义按钮,push有一个方法
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{}
在这个方法中viewController是push的对象
但是要判断这个viewController是不是根控制器
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
if (self.childViewControllers.count > 0) { // 非根控制器
// 非根控制器才需要设置返回按钮
// 设置返回按钮
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton setTitle:@"返回" forState:UIControlStateNormal];
[backButton setImage:[UIImage imageNamed:@"navigationButtonReturn"] forState:UIControlStateNormal];
[backButton setImage:[UIImage imageNamed:@"navigationButtonReturnClick"] forState:UIControlStateHighlighted];
[backButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[backButton setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
[backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
[backButton sizeToFit];
// 注意:一定要在按钮内容有尺寸的时候,设置才有效果
backButton.contentEdgeInsets = UIEdgeInsetsMake(0, -25, 0, 0);
// 设置返回按钮
viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
}
// 这个方法才是真正执行跳转
[super pushViewController:viewController animated:animated];
}
如何设置自定义导航控制器全局返回按钮 --- ios
标签:
原文地址:http://www.cnblogs.com/beNabenen/p/5432913.html