uitableview - UITableViewCell - When are the bounds properly set in iOS 10 -


i want create round uiview (myview) inside uitableviewcell

prior ios 10 using func awakefromnib() that:

class mycell: uitableviewcell {  @iboutlet var myview: uiview!      override func awakefromnib() {       super.awakefromnib()        print(myview.bounds.height)       myview.layer.cornerradius = myview.bounds.height/2       myview.layer.maskstobounds = true     } } 

myview height , set 30 via autolayout constraint in storyboard.

but print(myview.bounds.height) show 1000.0 in console. corner radius instruction set radius 500 , myview disappear completely.

is uitableviewcell life cycle change in ios 10 ? function view.bounds set change in ios 10 ? how can set cornerradius half view height in ios 10 ?

here minimal projet reproduce issue

to have result close want need add in uitableviewcontroller:

override func viewdidappear(animated: bool) {     super.viewdidappear(animated)     tableview.reloaddata() } 

but i'm quite sure not optimal ...

i had same problem , found 2 ways fix it. both enforce cell layout subviews

first solution:

override func awakefromnib() {     super.awakefromnib()     self.setneedslayout()     self.layoutifneeded()  } 

second way:

override func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell {     let cell = tableview.dequeuereusablecell(withidentifier: "cell", for: indexpath)       cell.setneedslayout()       cell.layoutifneeded() return cell } 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -