Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Size of default thumb image for iOS slider?

What is the exact size (width, height) of the (default) thumb image for the iOS slider? Is there perhaps some clever way to coax this out of the system (XCode, iOS)?

I tried

int thumbWidth = slider.currentThumbImage.size.width;

which I found here on this site, but it comes back with 0.

Additional question: The Xcode debugger shows this undocumented variable in the UISlider: CGFloat _hitOffset. Does anyone by chance know what it is and what it's for?

like image 573
JohnK Avatar asked May 04 '13 00:05

JohnK


3 Answers

What about this? Works for me:

CGRect trackRect = [self trackRectForBounds:self.bounds];
CGRect thumbRect = [self thumbRectForBounds:self.bounds trackRect:trackRect value:0];
CGSize thumbSize = thumbRect.size;
like image 98
Rudolf Adamkovič Avatar answered Oct 10 '22 18:10

Rudolf Adamkovič


If you want change UISlider appearance then use below method

[[UISlider appearance] setThumbImage:[UIImage imageNamed:@"yoursliderimage.png"] forState:UIControlStateNormal];

as well as below code would change you slider track also

UIImage *white = [UIImage imageNamed:@"16x16white.png"];

[movieTimeControl setMinimumTrackImage:[white stretchableImageWithLeftCapWidth:3.0 topCapHeight:0.0] forState:UIControlStateNormal];

[movieTimeControl setMaximumTrackImage:[white stretchableImageWithLeftCapWidth:3.0 topCapHeight:0.0] forState:UIControlStateNormal];

Aplle HIG document doesn't define any size for UISlider thumb image but it should be under normal image size.

like image 30
chandan Avatar answered Oct 10 '22 18:10

chandan


The best way is using a Resizable Image. But the slider thumb size is 23x23 if you don't want to make the image resizable

like image 3
lukaswelte Avatar answered Oct 10 '22 19:10

lukaswelte