I want to use a Scrollview on the middle 2/3 of the screen so I did the following:
1) I added a BaseView UIView to the middle 2/3 of my MainViewController and set the constraints to the following:
leading =0
trailing =0
top to safe area = 150
bottom to safe area = 150
2) I added a MyScrollView inside the BaseView and set the constraints as follows:
Note: All MyScrollview constraints remain RED after setting these constraints :>(
leading = 0
trailing = 0
top = 0
bottom = 0
3) I added a MyDataView UIView object inside the MyScrollView . The MyDataView starts at (0,0) and has a size of 500x500. I tried setting constraints on MyDataView to the following values but the top and leading constraints remain RED, most likely because the MyScrollView constraints are RED (see 2 above)
top=0
leading=0
width=500
height=500
4) In the viewDidLoad function I added the following:
ScrollView.delegate = self
ScrollView.contentsize = MyDataView.frame.size
5) I added various objects (buttons, labels, etc.) in the MyDataView UIView and tried to set constraints on these objects but the constraints are all RED as well.
Questions:
1) I am setting up the ScrollView properly so it can be used for 2/3 of the screen area only?
2) How can I set valid constraints for the objects placed in the MyDataView and have them be a nice BLUE color?
The point is how constraints are set for the contentView.
- remove the authorising constraints
- control-drag to scrollView and set top, leading, bottom, trailing
- change values to zero for those which were not
- add constraints on contentView, for width and height
Error (red badges) disappear. There may remain some harmless yellow warnings though.