xcode iOS滑块的默认拇指图像的大小?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16369258/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:19:30  来源:igfitidea点击:

Size of default thumb image for iOS slider?

iosobjective-cxcodecocoa-touchuislider

提问by JohnK

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

iOS 滑块的(默认)拇指图像的确切大小(宽度、高度)是多少?是否有一些聪明的方法可以将其从系统(XCode,iOS)中哄骗出来?

I tried

我试过

int thumbWidth = slider.currentThumbImage.size.width;

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

我发现这里在这个网站,但它回来了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?

附加问题:Xcode 调试器在UISlider: 中显示了这个未记录的变量CGFloat _hitOffset。有没有人偶然知道它是什么以及它的用途?

回答by Rudolf Adamkovi?

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;

回答by chandan

If you want change UISlider appearance then use below method

如果您想更改 UISlider 外观,请使用以下方法

[[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.

Aplle HIG 文档没有为 UISlider 拇指图像定义任何大小,但它应该在正常图像大小以下。

回答by lukaswelte

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

最好的方法是使用可调整大小的图像。但是如果您不想调整图像大小,滑块拇指大小为 23x23

回答by Peteee24

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

WWDC 2012 合集中有一个关于 UI 定制的会话视频:

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

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

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

您可能会在这里找到答案。它也是关于 UISlider 定制的

回答by iPhoneNoob

Here is the swift 4 version:

这是 swift 4 版本:

yourSlider.setThumbImage(UIImage(named: "Knob"), for: .normal)