简体   繁体   English

UIButton图像/标题插入对齐问题

[英]UIButton image/title inset alignment issues

I'm having some troubles getting the contents of my button to be aligned correctly. 我在使按钮的内容正确对齐方面遇到麻烦。 I set the insets to align the button to how I want it in the interface builder like this: 我设置了插入物,以使按钮与界面构建器中的按钮对齐,如下所示:

在此处输入图片说明

but then when I run the app in simulator it looks like this: 但是当我在模拟器中运行该应用程序时,它看起来像这样:

在此处输入图片说明

this button is using autolayout for sizing and alignment so I suspect that plays a role, but I can't figure it out. 该按钮正在使用自动版式进行大小调整和对齐,因此我怀疑它发挥了作用,但我无法弄清楚。 I also tried to alter the insets programmatically inside of viewDidLoad but that doesn't seem to help at all. 我还尝试在viewDidLoad内以编程方式更改插图,但这似乎根本没有帮助。

any help is appreciated. 任何帮助表示赞赏。

So I didn't find a solution to this exact issue but I found another approach that did fix my visual issues: 因此,我没有找到解决此确切问题的方法,但找到了另一种确实解决了视觉问题的方法:

Instead of using constraints, I used the Stack View controls available since iOS 9 to get the placement/sizing I was looking for. 我没有使用约束,而是使用了iOS 9以来可用的Stack View控件来获取我一直在寻找的布局/大小。 Since I'm creating a button grid, I just used vertical and horizontal stacks nested to create the button grid. 由于我正在创建按钮网格,因此我只使用嵌套的垂直和水平堆栈来创建按钮网格。

After implementing the stack views, the image and text of the button line up correctly. 实施堆栈视图后,按钮的图像和文本正确对齐。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM