Xcode 8 UIButton约束不显示 [英] Xcode 8 UIButtons with constraints not showing up
问题描述
一切都很好,直到昨天我更新Xcode到版本8。
Everything used to work great until yesterday I updated Xcode to version 8.
如果我不使用任何约束,我可以看到按钮,
If I don't use any constraints, I can see the buttons but when I apply constraint(s) to the buttons they disappear, no matter what or how many constraints (height, vertical spacing, trailing etc...) I apply.
当我点按的时候,按钮,他们行为正常(事件总是发送,所以我认为他们实际位于那里(?))。我试图改变文字颜色,背景颜色,(甚至添加一个新的UIButton),但结束没有运气。我看不到按钮。当我改变中心视图的背景颜色
我可以看到这个变化的应用程序。最奇怪的部分是当我点击 Debug View Hierarchy
在Xcode看到发生了什么,一切看起来很好;
When I tap buttons, they act normal (events are always sent so I assume they are actually located there(?)). I tried changing text color, background color, (even adding a new UIButton) but ended with no luck. I can't see the buttons. When I change the background color of Centered View
I can see this change on the app. The weirdest part is when I click Debug View Hierarchy
on Xcode to see what is going on, everything looks fine there; I can see all buttons located as I expect.
在iPhone 5(iOS 9.3.5)和iPhone 6(iOS 10)上测试应用程式。
Testing the app both on iPhone 5 (iOS 9.3.5) and iPhone 6 (iOS 10).
使用Swift 2.3,iOS 10和Xcode 8。
I am using Swift 2.3, iOS 10 and Xcode 8.
这是Xcode 8上的一个错误吗?如何解决此问题?
Is this a bug on Xcode 8? How to resolve this issue?
UPDATE:
问题也发生在UILabel和UIImageView上。
I just realised same constraint problem occurs on UILabel and UIImageView too. They look fine without constraint but when I add any constraint they disappear.
推荐答案
我缺少将UIButton类设置为my自定义类。我检查了我的自定义类,并已经看到我在 awakeFromNib()
方法设置拐角半径。在我设置拐角半径之前,我调用 layoutIfNeeded()
这是我的案例中的解决方案。
I was missing the point of setting UIButton class to my custom class. I checked my custom class and have seen that I set corner radius on awakeFromNib()
method. I called layoutIfNeeded()
before I set corner radius which was the solution in my case.
这篇关于Xcode 8 UIButton约束不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!