UIButton 上未显示标题
我正在使用以下代码作为导航栏中带有标题的自定义后退按钮。但是,标题没有显示,有什么帮助吗?
注意:后退按钮图像是黑色的,与 ios 默认使用的图像相同,需要自定义操作处理程序,这就是为什么这样做。
backButton=[UIButton buttonWithType:UIButtonTypeCustom];
[backButton setImage:[UIImage imageNamed:@"backbutton.png"] forState:UIControlStateNormal];
[backButton setImage:[UIImage imageNamed:@"backbutton.png"] forState:UIControlStateSelected];
[backButton addTarget:self action:@selector(customBack) forControlEvents:UIControlEventTouchUpInside];
[backButton setFrame:CGRectMake(0,0,64,32)];
[backButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[backButton setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
[backButton setTitle:@"Encameo" forState:UIControlStateNormal];
[backButton setTitle:@"Encameo" forState:UIControlStateSelected];
self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithCustomView: backButton];
I am using the following code for a custom back button with title in the nav bar. However, the title is not being shown, any help ?
nb: the back button image is black and the same one thats used by default by ios, needed to customize the action handler, thats why did it this way.
backButton=[UIButton buttonWithType:UIButtonTypeCustom];
[backButton setImage:[UIImage imageNamed:@"backbutton.png"] forState:UIControlStateNormal];
[backButton setImage:[UIImage imageNamed:@"backbutton.png"] forState:UIControlStateSelected];
[backButton addTarget:self action:@selector(customBack) forControlEvents:UIControlEventTouchUpInside];
[backButton setFrame:CGRectMake(0,0,64,32)];
[backButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[backButton setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
[backButton setTitle:@"Encameo" forState:UIControlStateNormal];
[backButton setTitle:@"Encameo" forState:UIControlStateSelected];
self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithCustomView: backButton];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在按钮上设置图像,而不是您需要设置 UIButton 的背景图像,然后将显示您的标题。
像这样更改代码
You are setting image on button instead of this you need to set backgroundImage of UIButton then your title will be displayed.
Change the code like this