ios - Multiline label in collection view cell breaks after reuse -
i have custom uicollectionviewcell several ui elements, laid out using autolayout setup in code.
on larger devices (iphone 6 , up) works expected.
on smaller devices however, multiline uilabel breaks, (it seems) after reuse.
on initial display, first cell looks this:
after cell has been scrolled off screen , brought on again, looks this:
these constraints set on label:
descriptionlabel.centerxanchor.constraint(equalto: firstbutton.centerxanchor), descriptionlabel.leadinganchor.constraint(equalto: otherlabel.leadinganchor), descriptionlabel.topanchor.constraint(equalto: firstbutton.bottomanchor, constant: 15), secondbutton.topanchor.constraint(greaterthanorequalto: descriptionlabel.bottomanchor, constant: 20),
i feel it's greaterthanorequalto
constraint, if replace plain old equalto
constraint, layout goes wild , label shrinks down fit 1 line.
i've faced similar problem in uicollectionview
, found solution in preferredmaxlayoutwidth
property , widthanchor
productnamelabel.widthanchor.constraint(equalto: self.widthanchor, multiplier: 0.6) productnamelabel.preferredmaxlayoutwidth = self.frame.size.width * 0.6
it should fix problem.
Comments
Post a Comment