There is a UIScrollView and I’d like to programmatically put subviews in it. It’s ok, but how can I lay automatically the subviews next to each other?
Thanks in advance!
There is a UIScrollView and I’d like to programmatically put subviews in it. It’s
Share
You can’t. The view hierarchy in UIKit–like the view hierarchy in most UI frameworks–uses explicit layout.
Your comment asks about HTML-like floating; the box model stuff that HTML/CSS uses was designed to serve a very different goal (flowing document layout) than what UIKit is for, and so there’s no real analogy in the framework.
UIViews do support automatic re-layout on resize/frame change of the parent view (you can say whether a subview should resize, how, and where it should be “pinned” to), through the autoresizing mask property, but I don’t think that’s what you’re asking for.
You could, if you were inclined, build a set of methods, perhaps as a category on UIView, that let you add subviews that had their frame origins adjusted automatically based on existing subviews.