我在一个项目中有一个复杂的约束布局,我已将其复制并粘贴到另一个项目中。它在第二个项目中的工作在所有方面都是相同的,只是我需要用 UIButton
替换 UIImageView
。删除 UIImageView
也将删除我一开始努力正确平衡的约束。对于这个问题,有没有比删除并煞费苦心地重新创建约束更好的解决方案?
感谢阅读。
最佳答案
在您的复制 View 中,一切都很完美。执行以下步骤以获得简单的解决方案
- Drag a UIButton just beside UIImageView
- Put Same constraints as you put on UIImageView.
- After putting same constraints, Just delete UIImageView.
这样,它就不会打扰您的约束,您将获得 UIButton 而不是 UIImageView。
你也可以按照下面的方式做
- Drag a UIButton just beside UIImageView
- Put Same constraints as you put on UIImageView.
- Hold down Option Key, drag Button to View (SuperView)
- Hold Down Shift to add multiple Constraints at a time.
- After putting same constraints, Simply HIDE UIImageView. Making hidden will also save your changes in code, else I might crash where you have put UIImageView references and usage in Code. You can rename UIImageView to UIButton and change throughout code also :)
谢谢
编码愉快!
关于ios - Xcode:有没有办法将 Storyboard上的现有组件换成另一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35695913/