Is there any possibility to move from UIView to UIScrollView without destroying all the constraints and placement. The thing is I build the whole UI without testing it on iPhone 4 and now I see some views should be in Scroll View to work. I tried few tricks but nothing works. Constraints gets deleted. Below is the example picture of sample:
Now I want that test1 UIView to be Scroll View, I tried to put Scroll View inside test1 View and then recursively copy test1 inside scroll view and delete old elements but it didnt work (shown bellow)
If there is any way to convert UIView to UIScrollView without destroying constraints (even programatically) that would be great. Thanks
Simply replace the <view>
element by <scrollView>
in your XIB file:
Make a backup copy of your XIB file.
Edit your XIB file as plain text:
Replace the specific <view>
tag by <scrollView>
.
Replace attributes (see example below).
Keep the original id
attribute.
Replace the closing </view>
tag by </scrollView>
.
I choose my battles. I prefer constraints as code.
Example, before:
<view contentMode="scaleToFill"
translatesAutoresizingMaskIntoConstraints="NO"
id="ABC-XY-123">
...
</view>
After:
<scrollView
clipsSubviews="YES"
multipleTouchEnabled="YES"
contentMode="scaleToFill"
alwaysBounceVertical="YES"
translatesAutoresizingMaskIntoConstraints="NO"
id="ABC-XY-123">
...
</scrollView>
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