rehatkathuria / SnappingSlider

A beautiful slider control for iOS built purely upon Swift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Adding Slider into TableViewCell failed to fit the size of the screen

Zarjagen opened this issue · comments

I called this in my override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell function:

let QuantitySlider = SnappingSlider(frame: CGRectMake(0.0, 0.0, 10.0, 10.0), title: "Quantity")
        QuantitySlider.translatesAutoresizingMaskIntoConstraints = false
        cell.QuantitySliderView.addSubview(QuantitySlider)
        QuantitySlider.delegate = self

        QuantitySlider.frame = CGRectMake(0.0, 0.0, cell.QuantitySliderView.bounds.size.width * 0.5, 50.0)
        QuantitySlider.center = CGPointMake(cell.QuantitySliderView.bounds.size.width * 0.5, cell.QuantitySliderView.bounds.size.height * 0.5)

However, the slider doesn't seem to come in the right place. I also added

print(QuantitySlider.bounds)
print(cell.QuantitySliderView.bounds) 

in my method, and the result is
(0.0, 0.0, 258.0, 50.0)
(0.0, 0.0, 516.0, 68.0)

I try to fix the screen in my storyboard in to 5.5 inch iPhone size, and the result is around
(0.0, 0.0, 167.0, 50.0)
(0.0, 0.0, 334.0, 68.0)

I think this is where the problem is. By the way, my QuantitySliderView has constraints that keep it in the center of the cell, so it is not the case that my QuantitySliderView has problem. Please respond, thank you!

Hello - Are you able to post the complete class in a gist so that I may have a look?

Closing due to lack of response.