how to change the slider thumb image?

烂漫一生 提交于 2019-12-06 22:40:20

问题


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:@"sliderThumb@2x.png"] 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


回答1:


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"]];

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.




回答2:


[[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];



回答3:


Just provide a different size of sliderThumb@2x.png and all we work itself out.



来源:https://stackoverflow.com/questions/7371622/how-to-change-the-slider-thumb-image

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