I managed to increase the thumb size of my UISlider
with Swift
but the touch zone is still too small for my application.
How to programmatically increase the size of the touch zone for a UISlider
?
Should I re-implement a custom slider by myself?
Thank you!
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)
}
}
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
.
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