ios - How to center a bunch of horizontal views in a UIScrollView -
ios - How to center a bunch of horizontal views in a UIScrollView -
i have uiscrollview
fills width of device , contains several uiviews
laid out horizontally. views have same width, on iphone 1 has scroll see views, on ipad of views visible.
my question how can horizontally center views on screen? when available space big plenty display views, need centered when it's not big plenty display views can laid out now, left right.
the interface has been set exclusively in interface builder. scroll view set fill entire device width - leading , trailing superview. first view in scroll view has leading set superview it's stuck far left. lastly button has trailing set superview - far right of scroll view, define scrollable content area. each view in middle laid out relative view left of - leading previous button.
here's graphical representation of current layout:
here's graphical representation of i'd obtain:
additional info: scroll view doesn't have fill device width, transparent. when views visible want disable scrolling. need adaptive, such upon rotating device can alter layout if needed, because on iphone in landscape views should visible in portrait won't be.
you can seek setting contentinset
property of scroll view, has type of uiedgeinsets
. property provides scroll view amount of "padding", adding scrollable area.
you can determine how much space have @ end (right-hand side) of view, split 2, , utilize value provide equal-width padding on each side.
ios uiview uiscrollview autolayout
Comments
Post a Comment