iPhone/iPad UIButton TitleLabel 文本未出现
我创建了一个按钮网格。以下代码创建按钮并显示它们,但按钮上没有文本。有我缺少的设置吗? (Obj-C 回复没问题,我会双语)
RectangleF frame = new RectangleF (X + 3, Y + 3, cellWidth - 2, cellHeight - 2);
UIButton button = new UIButton (frame);
button.TitleLabel.Text = "Baha'i";
button.TitleLabel.Font = UIFont.FromName ("Helvetica-Bold", 15);
button.TitleLabel.TextColor = UIColor.Black;
button.TitleLabel.Frame = frame;
button.BackgroundColor = UIColor.FromWhiteAlpha(.5f,.5f);
this.AddSubview (button);
I created a grid of buttons. The following code creates the buttons and displays them, but there is no text on the button. Is there a setting I am missing? (Obj-C replies are fine, I'm bi-lingual)
RectangleF frame = new RectangleF (X + 3, Y + 3, cellWidth - 2, cellHeight - 2);
UIButton button = new UIButton (frame);
button.TitleLabel.Text = "Baha'i";
button.TitleLabel.Font = UIFont.FromName ("Helvetica-Bold", 15);
button.TitleLabel.TextColor = UIColor.Black;
button.TitleLabel.Frame = frame;
button.BackgroundColor = UIColor.FromWhiteAlpha(.5f,.5f);
this.AddSubview (button);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我想你想要
setTitle: forState:
I think you want
setTitle: forState:
UIButton继承自UIView,因此添加文本和图像的另一种方法是添加子视图。例子:
A UIButton inherits from UIView, so another way to add text and images, is to add subview. Example:
在这里,我以编程方式创建示例按钮,然后设置其普通控件状态的标题,您可以使用自己的按钮对象来设置标题字符串,此外,您还可以通过将 UIControlStateNormal 更改为另一个所需的值来设置另一个控件状态的标题文本州。
Here, I have create sample programmatically button, and then set the title for its Normal Control state, You can use your own button object for set the title string, additionally you can also set title text for another control states by change UIControlStateNormal to another required states.
就我而言(Swift 4)如下:
In my case (Swift 4) it was the following:
对于快速开发者-
For swift Developers-