uiview - iOS swift multi-line UILabel in a view -
i accomplish seen in image below in interface builder. 2 labels - 1 multi-line , 1 note - inside view , view centered horizontally on page. clear, cannot put width constraint on view or centering not work correctly. 
i can label actual hours multi-line when not in view when place in view , set top, left , right constraints - label reverts single line.
below constraints , attributes label in view , picture of ib when update frames. suggestions appreciated.

there constraints label work hours in it: 
this looks after update frames

either multi-line label, or outer view needs have width constrained in way, otherwise label expand width whatever needs accommodate text on 1 line. if line long enough, text run off edge of view, appears happening in last image.
after edit:
to make view centered when list of hours short, still allow view wide when hours list long, give outer view <= width constraint superview. in ib select view superview, , choose "equal widths", , edit <=. default hugging priority keep outer view small if list short, if list grows long enough go multiple lines, still have width constraint force so.
i found adding <= constraint in ib didn't work correctly on rotation. if label multi-line in portrait, , labelsview (the view containing 2 labels) expanded full width of screen, on rotation labelsview maintained same width, instead of adjusting new size. think bug in system. fortunately, adding same constraint in code, worked fine.
override func viewdidload() { super.viewdidload() view.addconstraint(nslayoutconstraint(item: labelsview, attribute: .width, relatedby: .lessthanorequal, toitem: self.view, attribute: .width, multiplier: 1, constant: 0)) }
Comments
Post a Comment