自定义 UINavigationItem 上的标题未显示
我正在使用自定义背景图像和标题创建自定义 UINavigationItem。显示了图像,但没有显示标题。可能出什么问题了? 我这样做:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"bar_button.png"] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:@"bar_button_black.png"] forState:UIControlStateSelected];
[button setBackgroundImage:[UIImage imageNamed:@"bar_button_black.png"] forState:UIControlStateHighlighted];
[button setTitle:@"Cancel" forState:UIControlStateNormal];
[button setTitle:@"Cancel" forState:UIControlStateSelected];
[button setTitle:@"Cancel" forState:UIControlStateHighlighted];
[button addTarget:self action:@selector(closeButtonClicked) forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(0, 0, 49, 30)];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
I'm creating custom UINavigationItem with custom background image and title. The image is shown but the title doesn't. What could be wrong?
I'm doing it this way:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"bar_button.png"] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:@"bar_button_black.png"] forState:UIControlStateSelected];
[button setBackgroundImage:[UIImage imageNamed:@"bar_button_black.png"] forState:UIControlStateHighlighted];
[button setTitle:@"Cancel" forState:UIControlStateNormal];
[button setTitle:@"Cancel" forState:UIControlStateSelected];
[button setTitle:@"Cancel" forState:UIControlStateHighlighted];
[button addTarget:self action:@selector(closeButtonClicked) forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(0, 0, 49, 30)];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要将图像设置为backgroundImage,而不是直接设置。如果你这样设置图像,
标题将不会显示
这样设置
You need to set image as backgroundImage not direct. If you set image like this
the title will not be displayed
set like this
我认为你必须删除:
之后,标题就会出现
I think you must remove:
After that, the title will appear
删除此行
或者您可以将标题颜色更改为其他颜色。我希望它能解决您的问题。
将其设置为 DrakgrayColor 或其他可以克服图像颜色的颜色。
Either remove this line
or you can change the Title color to some other color.i hope it will solve your problem.
make it to DrakgrayColor or some other color which can overcome your image color.
好的。找到了解决方法,但我不确定是否允许:
OK. Found a workaround, however I'm not sure whether it is allowed: