ios - Set UIView size to fit subViews -



i'm having uiview that's containing 2 uilabels, have dynamic heights. want uiview fit size of uilabels + padding. right i'm drawing labels , sets uiview's width , height constraints combined size of labels.

right i'm doing this:

func populatewithmessage(headline: string?, message: string) {     // sets text     self.headerlabel.text = headline     self.messagelabel.text = message      self.headerlabel.sizetofit()     self.messagelabel.sizetofit()      self.layoutsubviews()      // finding label greatest width     var longestlabel: uilabel!     if self.headerlabel.frame.width > self.messagelabel.frame.width {        longestlabel = self.headerlabel    } else {        longestlabel = self.messagelabel    }     let combinedlabelheight = self.headerlabel.frame.height + self.messagelabel.frame.height     // update container view's constraints    self.containerviewwidtconstraint.constant = longestlabel.frame.width + 10    self.containerviewheightconstraint.constant = combinedlabelheight + 10     self.updateconstraints() } 

unfortunately doesn't work :-/

ideas appreciated!

i'm using swift 2.3 , autolayout.

you can using storyboard itself.

set view's bottom constraint second uilabel. when height of label increases, uiview's height increases.

enter image description here

enter image description here


Comments

Popular posts from this blog

php - Auto increment employee ID -

php - isset function not working properly -

python - Evaluating the next line in a For Loop while in the current iteration -