I have TableViewController with multiple cells. I am setting the height of these cells in the heightForRowAt method:
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UIScreen.main.bounds.maxY / 15
}
When the device orientation is portrait, everything is working fine, but when its landscape, maxY is very small, so the cells are too small as well. I want them to have the same height whatever the orientation is. So how do I get the portrait device height even if the current orientation is landscape?
Ok, if found a pretty simple solution for this problem. I just use both width and height when calculating the row height, so the orientation doesn't matter.
When you do that, you just have to find the right constant to divide the addition by, so that it looks good.
That is my code now:
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return (UIScreen.main.bounds.maxY+UIScreen.main.bounds.maxX) / 28
}