我如何自定义导航返回按钮在iOS 7及以上没有标题?(即只使用箭头)
self.navigationItem.leftBarButtonItem = self.editButtonItem;
我只是想知道它们是否有self。backbuttonitem;
OR
像这样的东西?
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemBACK
target:self action:@selector(back)];
只用一张图片!
OBJ - c:
- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Icon-Back"]
style:UIBarButtonItemStylePlain
target:self.navigationController
action:@selector(popViewControllerAnimated:)];
self.navigationItem.leftBarButtonItem = backButton;
}
斯威夫特4:
let backBTN = UIBarButtonItem(image: UIImage(named: "Back"),
style: .plain,
target: navigationController,
action: #selector(UINavigationController.popViewController(animated:)))
navigationItem.leftBarButtonItem = backBTN
navigationController?.interactivePopGestureRecognizer?.delegate = self
Icon-Back.png
Icon-Back@2x.png
Icon-Back@3x.png
其实很简单,我是这么做的:
Objective - C
// Set this in every view controller so that the back button displays back instead of the root view controller name
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
斯威夫特2
self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .Plain, target: nil, action: nil)
斯威夫特3
self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
把这一行放到推送到堆栈(前一个视图控制器)的视图控制器中。新按下的视图控制器返回按钮现在将显示你为initWithTitle所放的任何东西,在本例中是一个空字符串。