ios - Programatically setting constraints on UITableViewCell -


i ve been using storyboards far set constraints attempting learn how things programatically.the issue @ hand:

a table needs return cell in cellforrowat. there need add uilabel element constraint top left bottom , right anchors. table cell height set automatic dont know size of label be. code looks follows:

var uil = uilabel()              cell.addsubview(uil)             uil.leftanchor.constraint(equalto: cell.leftanchor).isactive = true             uil.rightanchor.constraint(equalto: cell.rightanchor).isactive = true             uil.topanchor.constraint(equalto: cell.topanchor).isactive = true             uil.bottomanchor.constraint(equalto: cell.bottomanchor).isactive = true             uil.numberoflines = 0;             uil.text = "some variable sized text really"; 

if dont give frame uilabel see nothing. if using like

uilabel(frame : cgrect(x:0 , y:0 , width : 100 , height : 100 ) 

then expected see label constraints dont apply. missing? shouldn't constraints enough descriptive?

thank all

if dynamically adding views need set view.translatesautoresizingmaskintoconstraints = false

for more details click here

and apply below constraints work.

// align lbl left , right cell.addconstraints(nslayoutconstraint.constraintswithvisualformat("h:|-8-[view]-8-|", options: nslayoutformatoptions(rawvalue: 0), metrics: nil, views: ["view": lbl]));  // align lbl top , bottom cell.addconstraints(nslayoutconstraint.constraintswithvisualformat("v:|-8-[view]-8-|", options: nslayoutformatoptions(rawvalue: 0), metrics: nil, views: ["view": lbl])); 

Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -