简体   繁体   中英

How to copy auto-layout constraints in IB from one view to another?

I have several screens with the same elements inside - Header image with label inside. I use auto-layout to fix screen size change from 4" to 3,5" and transparent status bar at the top of the screen (iOS 6 vs iOS 7). After loosing some time playing with constraints I have one form which header image and label behaviour is ok. The problem is that I can not repeat the same steps so I can have all other forms the same constraints for header image and label. It is possible to apply the same constraints to all screens for header image and label and after that to fix other issues which will appear with other constraints? I suppose that other way is to generate those constraints from code, but I am not sure if there is such option from Interface Builder?

I haven't been able to find a good way. What I have ended up doing is duplicating the view controller and then making any necessary changes.

This is a hacky work-around:

  1. View the source code for the view or controller that you're wanting to copy (you didn't specify)

  2. Copy the source code

  3. Create a new view or controller of the same type as your original one, and open it in the source code view

  4. Paste the copied source code into it. All of the constraints and details will be retained.

  5. Note- you should change the view/controller title in the source code, otherwise it will be controlled by the original view/controller class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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