Jojo44 Jojo44 - 1 year ago 522
iOS Question

Increase touch target size of UISlider with Swift

I managed to increase the thumb size of my

but the touch zone is still too small for my application.

How to programmatically increase the size of the touch zone for a

Should I re-implement a custom slider by myself?

Thank you!

Answer Source

Subclass UISlider and in your custom class of slider add this method,

  func pointInside(_ point: CGPoint, withEvent event: UIEvent?) -> Bool {
    var bounds: CGRect = self.bounds
    bounds = CGRectInset(bounds, -10, -15)
    return CGRectContainsPoint(bounds, point)

Then create object of that subclass when you used slider.

If you have used slider in interfacebuilder (storyboard) then set it's class to that custom slider class from identity inspector.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download