views:

478

answers:

2

Hello,

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.

A: 

I believe that you may want to look at thumbRectForBounds:trackRect:value:

jessecurry
Unfortunately, UISlider doesn't use the return from this function to determine the touch region of the slider thumb.
Allen Pike
+1  A: 

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.

Allen Pike
Small correction: I think you want to pass a negative SIZE_EXTENSION_Y value to CGRectInset to make the rect larger.
Kelan