After I updated to Xcode 9, UITableView in iOS 10 device is behaving very strangely. The tableView cell sizes are not maintained. It it resizing by itself and not following the constraints and cell sizes I had explicitly coded. The gap between the tableView cells is black all of a sudden. However, these layout issues are not reciprocated in iOS 11 handset. In a nutshell, the layout is completely screwed in iOS 10 devices. Is anyone else having backward compatibility after updating to Xcode 9? If so how did you resolve it.
To change the frame width of the custom table View cell cell I am using the frame property. The code I am using is
override var frame: CGRect {
//Decrease frame width of the tableViewCell
get {
return super.frame
}
set (newFrame) {
var frame = newFrame
frame.origin.x += 8
frame.size.width = frame.size.width-16
super.frame = frame
}
}
Below is how the tableViewCell is presented in iOS 11 which is correct
this is how the tableViewCell is presented in iOS 10 which is incorrect
[
As you can see the gap from right margin to the tableView Cell is more.
Throw away your existing code. Don't touch the cell's frame in any way.
To make cells that look narrower than the table, give the cell a clear background and put an opaque view inside the content view that is inset from the cell's bounds (or you could use the cell's background view for this). Use autolayout to configure this, so that it works regardless of screen size.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With