ios - Custom view not resizing with auto-layout -


note: don't have check library understand question, brought reference.

i implemented didatepicker in xcode. way inserted in view is: inserted uiview viewcontroller auto-layout, @ identity inspector set class didatepicker.

enter image description here

the problem is, didatepicker doesn't resize view's size. thinking possible solution may be, set didatepicker view's class in viewdidload, though don't know how that.

my question is: if theory right, how can set didatepicker view's class. if said not true, how can make didatepicker resize view?


didatepicker has collectionview; here how it's defined:

uicollectionviewflowlayout *collectionviewlayout = [[uicollectionviewflowlayout alloc] init];  [collectionviewlayout setitemsize:cgsizemake(kdidatepickeritemwidth, cgrectgetheight(self.bounds))];  [collectionviewlayout setsectioninset:uiedgeinsetsmake(0, kdidatepickerspacebetweenitems, 0, kdidatepickerspacebetweenitems)];  [collectionviewlayout setminimumlinespacing:kdidatepickerspacebetweenitems];  _datescollectionview = [[uicollectionview alloc] initwithframe:self.bounds collectionviewlayout:collectionviewlayout];  

so had same exact problem you.

the problem when build didatepicker builds own collection view based on view's original frame rather frame after auto-layout takes place.

the way circumvent problem not making storyboard uiview of class didatepicker. instead, use normal uiview , create didatepicker instance same frame uiview in viewdidload method.

here example. datepickerview uiview storyboard.

datepicker = didatepicker(frame: cgrectmake(datepickerview.frame.origin.x, datepickerview.frame.origin.y , self.view.frame.width, datepickerview.frame.height)); self.view.addsubview(datepicker!); 

if doesn't work try changing frame , adding datepickerview subview instead of main view.

hope helps!


Comments