xcode 如何更改滑块拇指图像?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7371622/
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
how to change the slider thumb image?
提问by Nik's
I have to create my own customized slider. I am trying to change the thumb image,background of the slider and in the some test like slide to unlock. I have tried like this but its not working
我必须创建自己的自定义滑块。我正在尝试更改拇指图像、滑块的背景,并在一些测试(如滑动解锁)中进行更改。我试过这样但它不工作
CGRect frame = CGRectMake(0.0, 219.0, 323.0, 20.0);
UISlider *myslider = [[UISlider alloc] initWithFrame:frame];
[myslider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
[myslider setBackgroundColor:[UIColor clearColor]];
[myslider setThumbImage: [UIImage imageNamed:@"[email protected]"] forState:UIControlStateNormal];
myslider.minimumValue = 0.0;
myslider.maximumValue = 50.0;
myslider.continuous = YES;
myslider.value = 15.0;
[self.view addSubview:myslider];
But in this the size of thumb pic is very big.How to reduce the thumb pic size....and how to give the slider background and text.Please help me out
但是在这种情况下,拇指图片的大小非常大。如何减小拇指图片的大小....以及如何为滑块提供背景和文字。请帮帮我
回答by Darshit Shah
[[UISlider appearance] setThumbImage:[UIImage imageNamed:@"ball.png"] forState:UIControlStateNormal];
[slider setMinimumTrackImage:[[UIImage imageNamed:@"volume_slider_oragne.png"] stretchableImageWithLeftCapWidth:0.3 topCapHeight:0.0] forState:UIControlStateNormal];
[slider setMaximumTrackImage:[[UIImage imageNamed:@"volume_strap_gry.png"] stretchableImageWithLeftCapWidth:0.3 topCapHeight:0.0] forState:UIControlStateNormal];
回答by max_
To set the background colour of the slider, I would presume that you can set the property backgroundColor
to [UIColor colorWithPatternImage:[UIImage imageNamed:@"slider background"]];
要设置滑块的背景颜色,我假设您可以将属性设置backgroundColor
为[UIColor colorWithPatternImage:[UIImage imageNamed:@"slider background"]];
Also, images that have the appending ending of @2x
, mean that they are twice the size of the standard copy. This is for retina displays only, you should not use it in a UIImage
on a standard (legacy) device. Try setting the image name to @"sliderThumb.png"
instead, as long as you have the legacy copy of the image.
此外,附加结尾的图像@2x
意味着它们的大小是标准副本的两倍。这仅适用于视网膜显示器,您不应在UIImage
标准(传统)设备上使用它。@"sliderThumb.png"
只要您拥有图像的旧副本,请尝试将图像名称设置为。
回答by chewy
Just provide a different size of [email protected] and all we work itself out.
只需提供不同大小的 [email protected] 和我们自己解决的所有问题。