UIButton of type UIButtonTypeCustom will not display Title (iPhone)(UIButtonTypeCustom 类型的 UIButton 将不显示标题 (iPhone))
问题描述
我一定忽略了一些非常明显的东西??但是我的按钮正确显示了它的图像和大小,但我根本无法显示标题.
我做了一个非常简单的测试,当我这样做时,标题甚至没有出现:
CGRect frameBtn = CGRectMake(160.0f, 150.0f, 144.0f, 42.0f);UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];[按钮 setImage:[UIImage imageNamed:@"left_halfscreen_button.png"] forState:UIControlStateNormal];[按钮 setTitle:@"Hello" forState:UIControlStateNormal];[按钮 setFrame:frameBtn];NSLog(@"Title:%@", [button currentTitle]);//打印标题:你好[自我添加子视图:按钮];
我有一个为我生成自定义按钮的工厂类,我认为我在那里搞砸了一些细节,所以我将上面的代码直接移动到我的
UIView
中,标题仍然是空白的.这是一个错误还是我只是错过了眼前的一些东西.
谢谢你的眼睛:)
解决方案图片覆盖标题,需要将图片设为背景图片才能显示标题.
<上一页>[按钮setBackgroundImage:[UIImage imageNamed:@left_halfscreen_button.png"]forState:UIControlStateNormal];
I must have overlooked something completely obvious?? but my button displays its image and size correctly, but I simply can't get the Title to show up.
I did a really simple test, the Title does not even show up when I do this:
CGRect frameBtn = CGRectMake(160.0f, 150.0f, 144.0f, 42.0f);
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"left_halfscreen_button.png"] forState:UIControlStateNormal];
[button setTitle:@"Hello" forState:UIControlStateNormal];
[button setFrame:frameBtn];
NSLog(@"Title:%@", [button currentTitle]);
//prints "Title:Hello
[self addSubview:button];
I have a factory class that generates custom buttons for me and I thought I messed some detail up there, so I moved the above code directly into my UIView
, the title is still blank.
Is this a bug or am I simply missing something right in front of my eyes.
Thank you for the extra set of eyes:)
Image overrides title, you need to make the image a background image to show the title.
[button setBackgroundImage:[UIImage imageNamed:@"left_halfscreen_button.png"] forState:UIControlStateNormal];
这篇关于UIButtonTypeCustom 类型的 UIButton 将不显示标题 (iPhone)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UIButtonTypeCustom 类型的 UIButton 将不显示标题 (iPhone)


基础教程推荐
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01