为什么navigationbar
无法显示leftButton和rightButton,但是如果我单击那里,它就会响应。我将背景色设置为蓝色,但是看起来不太清晰,就像navigationItem
上的内容一样。
最佳答案
以这种方式添加按钮。
UIImage *addImage = [UIImage imageNamed:@"add.png"];
UIButton *addButton = [UIButton buttonWithType:UIButtonTypeCustom];
[addButton setFrame:CGRectMake(0, 0, addImage.size.width, addImage.size.height)];
[addButton setBackgroundImage:addImage forState:UIControlStateNormal];
[addButton addTarget:self action:@selector(btnAddClicked:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:addButton];
self.navigationItem.leftBarButtonItem = barButtonItem;
self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
您可以从storyBoard更改barTintColor
关于ios - 导航buttonItem无法显示,且navigationItem背景颜色不是很清晰,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39162106/