7

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?

Community
  • 1
  • 1
JohnK
  • 6,865
  • 8
  • 49
  • 75
  • working with sizes, you shouldn't use `NSInteger`, better use CGFloat so you can save the exact value! – Alex Cio Jun 12 '15 at 09:10

5 Answers5

10

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;
Rudolf Adamkovič
  • 31,030
  • 13
  • 103
  • 118
4

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.

chandan
  • 2,453
  • 23
  • 31
3

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

lukaswelte
  • 2,951
  • 1
  • 23
  • 45
0

There is a session video about UI customization in the WWDC 2012 collection:

https://developer.apple.com/videos/wwdc/2012/?id=216

You might find your answer here. Its about UISlider customization too

Peteee24
  • 510
  • 4
  • 8
0

Here is the swift 4 version:

yourSlider.setThumbImage(UIImage(named: "Knob"), for: .normal)
iPhoneNoob
  • 173
  • 1
  • 6
  • 19