Increase touch target size of UISlider with Swift
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
.
Swift 3 update of Lion's great answer:
import UIKit
class CustomSlider: UISlider {
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
var bounds: CGRect = self.bounds
bounds = bounds.insetBy(dx: -10, dy: -15)
return bounds.contains(point)
}
}