ios - How can I let the width of a control be the width of the current device? -


for example, create uitableview in storyboard , want uitableviewcell fixed proportion (e.g. 16:1).

  1. example: if on 5s, want uitableviewcell frame (width:320, height:20).

  2. example: if on 6plus, want uitableviewcell frame (width:640, height:40).

for uitableviewcell it's easy, implement method in uitableviewdelegate:

func tableview(tableview: uitableview, heightforrowatindexpath indexpath: nsindexpath) -> cgfloat {     return tableview.frame.size.width / 16.0 } 

and in order place subviews accordingly, you'd need add constraints them. else uitableviewcell little tricky, again - autolayout , constraints friends.


Comments