Joseph Beuys' Mum
Joseph Beuys' Mum

Reputation: 2284

Xcode: Is there a way to swap an existing component on a storyboard for another

I have a complex constraints layout in one project I have copied and pasted to another. Its job in this second project is identical in all respects except that I need to replace a UIImageView with a UIButton. Deleting the UIImageView will also remove the constraints I worked hard to balance correctly in the first place. Is there better solution to this problem than deleting and painstakingly recreating the constraints?

Thank you for reading.

Upvotes: 1

Views: 247

Answers (1)

Chatar Veer Suthar
Chatar Veer Suthar

Reputation: 15639

Everything is perfect in your copying view. Do the following steps to get an easy solution

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

By this, it will not disturb your constraints and you will get UIButton instead of UIImageView.

You can also do as below

  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 :)

Thanks

Happy Coding!

Upvotes: 1

Related Questions