ios - Adjust UIScrollView's contentSize with an embedded UIView? -
i have uiscroll view contains 1 subview. subview called contentview
is uiview. here did in viewdidload()
:
self.scrollview = uiscrollview() self.view.addsubview(self.scrollview) self.scrollview.backgroundcolor = uicolor.yellowcolor() // pin edges edges of superview (self.view) self.scrollview.snp_makeconstraints { (make) -> void in make.edges.equalto(self.view) } // create contentview self.contentview = uiview() self.contentview.backgroundcolor = uicolor.redcolor() self.scrollview.addsubview(self.contentview) // pin edges of contentview scrollview self.contentview.snp_makeconstraints { (make) -> void in make.edges.equalto(self.scrollview) } let myview = uiview(frame: cgrectmake(100, 100, 20, 300)) myview.backgroundcolor = uicolor.greencolor() self.contentview.addsubview(myview)
the result this:
there ne red contentview shown in previous screen shot.
next, tried adjust size of contenview in viewdidlayoutsubviews()
:
let newsize: cgsize = self.contentview.systemlayoutsizefittingsize(uilayoutfittingcompressedsize) println("newsize: \(newsize)")
the result is:
newsize: (0.0, 0.0)
how can either setup correct size of contentview or set correct size of uiscrollview's contentsize?
have tried setting var contentsize: cgsize
of uiscrollview? documentation says
discussion
unit of size points. default size cgsizezero.
if don't know size of content view, recommend setting
scrollview.autoresizingmask = (uiviewautoresizingflexiblewidth| uiviewautoresizingflexibleheight);
and
scrollview.autoresizessubviews = yes;
for measure.
Comments
Post a Comment