UIButton 标题不显示 [英] UIButton title not displaying

查看:52
本文介绍了UIButton 标题不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我刚开始用 Swift 进行开发.


I just started developing in Swift.

我动态创建了一个 UIButton 并将其添加到视图中.我的问题是视图没有显示按钮.

I created an UIButton dynamically and added it to the View. My issue is the view is not displaying the button.

我的代码:

var button:UIButton = UIButton();
button.frame = CGRect(x: 100, y: 250, width: 100, height: 50);
button.setTitle("Midhun", forState: UIControlState.Normal);
self.view.addSubview(button);

然后我将图像添加到按钮然后显示:

Then I added image to the button and then it is showing:

button.setImage(UIImage(named: "step_first.jpg"), forState: UIControlState.Normal);

我无法弄清楚发生了什么.请帮忙

I couldn't figure out what is happening. Please help

推荐答案

我确实发现了这个问题.

I actually figured out the issue.

在 Swift 中,UIButton 的标题是白色的.

In Swift the title of UIButton is white.

我更改了父视图的背景颜色,现在显示了.

I changed the background color of parent View, now it is showing.

self.view.backgroundColor = UIColor.black

这篇关于UIButton 标题不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆