本文介绍了将自定义按钮添加到UINavigationItem LeftBarButtonItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
谁能告诉我为什么此代码不起作用?
Could anyone tell me why this code does not working?
self.backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.backButton setImage:[UIImage imageNamed:@"back_arrow.png"]
forState:UIControlStateNormal];
self.backButton.contentMode = UIViewContentModeCenter;
[self.backButton addTarget:self
action:@selector(backButtonAction:)
forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.backButton];
[navigationItem setLeftBarButtonItem:backButtonItem animated:NO];
navigationItem.hidesBackButton = YES;
leftBarButtonItem
上没有任何内容.那是问题.
Nothing appears on the leftBarButtonItem
. That's the problem.
推荐答案
来自文档:
因此,如果在第2行中设置框架,您应该会看到一些东西,例如:
So you should see something if you set the frame in line 2, eg:
self.backButton.frame = CGRectMake(0, 0, 40, 20);
这篇关于将自定义按钮添加到UINavigationItem LeftBarButtonItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!