My goal is to create a bigger UISlider with 35 pixels height for the thumb image.
I subclassed UISlider and added the method :
- (CGRect)trackRectForBounds:(CGRect)bounds
{
return CGRectMake(bounds.origin.x, bounds.origin.y, self.bounds.size.width, 50);
}
Then I set the thum image from my controller using setThumbImage:
My bigger thumb is well displayed.
The problem I have is that the tracking zone is still the same around 19 px height, how to extend it to 50 ?
Thanks
T.
Increase UISlider thumb hit area by increasing the height of the UISlider frame. This approach avoids any offset and subsequent need to correct the slider frame.
- (void)viewDidLoad{
[super viewDidLoad];
//expand slider hit area
self.slider.frame = CGRectInset(self.slider.frame, 0, -10);
}
A long-standing problem with the iPhone OS' UISlider control is that you can't make it taller. More specifically, you can make it look taller by specifying taller images for its thumb and track, but the touch area stays as a tiny 23px tall.
Michael Patricios has published a way to make the default sliders a lot easier to touch, and a variation of that technique can handle larger sliders. What you need to do is subclass UISlider, and override pointInside in your class:
// How many extra touchable pixels you want above and below the 23px slider
#define SIZE_EXTENSION_Y 10
- (BOOL) pointInside:(CGPoint)point withEvent:(UIEvent*)event {
CGRect bounds = self.bounds;
bounds = CGRectInset(bounds, 0, SIZE_EXTENSION_Y);
return CGRectContainsPoint(bounds, point);
}
In Interface Builder, set the slider to use your new UISlider subclass, and you now have a slider with a 43px touchable height.
I'm using this solution :)
CGRect sliderFrame = self.mySlider.frame;
sliderFrame.size.height = 142.0;
[self.mySlider setFrame:sliderFrame];
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