Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bigger UISlider ok but tracking zone problem

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.

like image 444
thierryb Avatar asked Sep 16 '09 23:09

thierryb


3 Answers

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);

}
like image 173
Brody Robertson Avatar answered Nov 16 '22 22:11

Brody Robertson


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.

like image 29
Allen Pike Avatar answered Nov 16 '22 20:11

Allen Pike


I'm using this solution :)

CGRect sliderFrame = self.mySlider.frame;    
sliderFrame.size.height = 142.0; 
[self.mySlider setFrame:sliderFrame];
like image 11
alexhajdu Avatar answered Nov 16 '22 22:11

alexhajdu