Size of default thumb image for iOS slider?

你说的曾经没有我的故事 提交于 2019-12-05 06:16:59

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;

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.

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

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

Here is the swift 4 version:

yourSlider.setThumbImage(UIImage(named: "Knob"), for: .normal)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!