ios - Xcode:有没有办法将 Storyboard上的现有组件换成另一个

标签 ios xcode swift uistoryboard xcode-storyboard

我在一个项目中有一个复杂的约束布局,我已将其复制并粘贴到另一个项目中。它在第二个项目中的工作在所有方面都是相同的,只是我需要用 UIButton 替换 UIImageView。删除 UIImageView 也将删除我一开始努力正确平衡的约束。对于这个问题,有没有比删除并煞费苦心地重新创建约束更好的解决方案?

感谢阅读。

最佳答案

在您的复制 View 中,一切都很完美。执行以下步骤以获得简单的解决方案

  1. Drag a UIButton just beside UIImageView
  2. Put Same constraints as you put on UIImageView.
  3. After putting same constraints, Just delete UIImageView.

这样,它就不会打扰您的约束,您将获得 UIButton 而不是 UIImageView。

你也可以按照下面的方式做

  1. Drag a UIButton just beside UIImageView
  2. Put Same constraints as you put on UIImageView.
  3. Hold down Option Key, drag Button to View (SuperView)
  4. Hold Down Shift to add multiple Constraints at a time.
  5. 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/

相关文章:

ios - 如何打印json数据

ios - 在运行时设置位置模拟器 City/GPX

iphone - 在设备上进行测试时向SIGABRT发出信号,它可在模拟器上运行。简易代码

ios - 如何在 iOS 后台从 Alamofire 获得稳定的连接

ios - UICollectionView 粘性标题在集合过度滚动时插入部分后消失一段时间(弹跳效果)

ios - 因约束而导致崩溃

ios - Facebook SDK v4和Parse SDK

ios - 如何跟踪变量在哪一点被更改?

html - 如何在 iOS 中从 NSAttributedString 获取 html 字符串

ios - 在 alertController 中带有按钮的自定义 uiview 在 iOS 中不起作用