中心对齐UIBUTTON XCODE以编程方式
我正在尝试以编程方式将Uibutton的文本集中。
就是我希望uibutton的外观(我使用了接口构建器):
这 是uibutton在编程之后的样子:
这就是Uibutton的外观就像我以编程方式设置并试图像第一张图片一样将文本设置为中心:
是我试图将其居中的代码:
previousPageButton.titleLabel?.numberOfLines = 0
previousPageButton.titleLabel?.textAlignment = .center
I’m trying to center the text of UIButton programmatically.
This is what I want the UIButton to look like (I used the interface builder):
This is what the UIButton looks like after I set it programmatically:
And this is what the UIButton looks like after I set it programmatically and tried to center the text like in the first picture:
This is the code that I used to try to center it:
previousPageButton.titleLabel?.numberOfLines = 0
previousPageButton.titleLabel?.textAlignment = .center
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是我已将“归因于”接口构建器中的标题设置为。我只需要将其设置为“普通”,现在正在工作。
The problem was I had set up "attributed" to the title in interface builder. I just had to set it to "plain" and it's working now.
使用新按钮配置进行操作,设置您的按钮:
在ViewDidload集合设置约束:
这是结果:
Do it with new button configuration, set your button:
in viewDidLoad set constraints:
This is the result: