ios - Custom UIView from XIB has no height in UIStackView -


i adding custom uiview uistackview inside uiscrollview. custom uiview created xib without fixed width. use autolayout horizontally constrain custom view uistackview. subviews in custom view have either fixed height or intrinsic height (i.e. labels).

when add uiview uistackview, pile on top of each other, if have no height. how ensure correct height of custom view inside stack view based on constraints interface builder?

here how adding custom view uistackview:

customview *customview = [customview loadfromxib]; // helper load xib customview.translatesautoresizingmaskintoconstraints = no; [_stackview addarrangedsubview:customview]; [_stackview addconstraints:[nslayoutconstraint constraintswithvisualformat:@"h:|[customview]|" options:nslayoutformatdirectionleadingtotrailing metrics:nil views:@{@"customview": customview}]]; 

i suspect issue involves intrinsiccontentsize of custom view, think set constraints specified xib in interface builder.

i have come across problem in swift, every custom view of mine added uistackview seems appear in 0 height , pile on top of each other.

what did resolve problem set height , width constraint custom view before added in uistackview.

let customview = customview(frame: cgrect(x: 0, y: 0, width: self.view.frame.width, height: 100), customobject: self.customobject)  customview.widthanchor.constraint(equaltoconstant: customview.frame.width).isactive = true customview.heightanchor.constraint(equaltoconstant: customview.frame.height).isactive = true  contentstackview.insertarrangedsubview(customview, at: 0) 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -