I've created a custom range slider in an iOS project using this tutorial: https://www.raywenderlich.com/7595-how-to-make-a-custom-control-tutorial-a-reusable-slider
Using Xcode 10.1 and Swift 4.2.1.
The only difference is, I've removed the viewDidLayoutSubviews()
part because I've done it in the storyboard. Here I placed a UIView in the storyboard, set its contraints, set its class to RangeSlider
and created an @IBOutlet weak var rangeSlider: RangeSlider!
in the view controller.
I'm using a static table view but with a dynamic cell height:
override func viewDidLoad() {
...
self.tableView.rowHeight = UITableView.automaticDimension
self.tableView.estimatedRowHeight = 80.0
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
If I change the font size the cells height gets adapted, which is what I want, but somehow the cell with the rangeSlider in it, covers one half of the rangeSlider. It doesn't matter if I play around with the font size, rotate the screen etc. It's always covered.
Can someone help? Am I missing something?
For automatic dimension to work, you must have an unbroken chain of constraints from the top of the contentView
to the bottom and every item in that chain need to have an explicit height or an intrinsicContentSize.
From what I can tell from the tutorial they do not define an intrinsicContentSize for the custom slider. UIKit gives controls that have an intrinsicContentSize a width and height constraint equal to their intrinsicContentSize if you don't otherwise constrain them. So 1) implement intrinsicContentSize
or 2) manually add a fixed height constraint IN ADDTION TO a top and bottom constraint to the tableViewCell's content view.