swift - How to get resizing tableView cell with different content without deleting constraints in iOS -
i have tableview cell different content(views, labels, imageviews) in 1 cell. in cells content can not full. how can use resizing cells without removing , adding constraints? thanks.
one of possible solutions problem:
- add constraints hidden state priority 1000
- add constraints resized state lower priority (ex 750)
- save constraints only hidden state
iboutlet
collection - save constraints only resized state
iboutlet
collection
code:
@iboutlet var hiddenconstraints: [nslayoutconstraint] = [] @iboutlet var visibleconstraints: [nslayoutconstraint] = [] func hide(_ hide: bool) { hiddenconstraint in self.hiddenconstraints { hiddenconstraint.isactive = hide } visibleconstraint in self.visibleconstraints { visibleconstraint.isactive = !hide } self.layoutifneeded() }
there faster solution:
- move content can hidden container view
- set height constraint container view
- change code height constraint constant 0 if hidden or proper height if visible
code:
@iboutlet var heightconstraint: nslayoutconstraint! func hide(_ hide: bool) { self. heightconstraint.constant = hide ? 0 : 150 //estimated height self.layoutifneeded() }
this not approach, lead constraint crashes @ runtime. prefer use first one.
also need update cell table move other cells or down.
Comments
Post a Comment