In Interface Builder, I have a UIView
with a complex set of constraints attached to it. What is the best way of exchanging this UIView
for a UIImageView
without having to recreate all the constraints?
Deleting the UIView
deletes its constraints too.
NB: Simply setting the UIView
's class to UIImageView
won't work because it doesn't give me all the changeable attributes associated with the image view.
fill distribution creates constraints attaching the top of the first arranged subview to the top of the stack view, and the bottom of the last arranged subview to the bottom of the stack view. It also creates a constraint between the top/bottom of adjacent subviews with the spacing of the stack view.
Auto Layout defines margins for each view. These margins describe the preferred spacing between the edge of the view and its subviews. You can access the view's margins using either the layoutMargins or layoutMarginsGuide property.
Infuriatingly, there is no smart answer to this. The IB simply has no ability to let you switch control types. Oh, Xcode, you do let us down.
However there is a hacky way of doing it, described by this blog: http://codenetwaves.blogspot.com.br/2012/09/change-view-to-scrollview-in-xcode.html
The steps are:
Right-click the storyboard, select Open As --> Source Code
The storyboard is an XML file. Find the view you want to change. Replace <view ...> ... </view>
with <imageView ...> ... </imageView>
. Don't change anything else.
Right-click the storyboard again, and open in Interface Builder. The views have been converted to UIImageView
s and you can access all the normal UIImageView
attributes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With