自定义滑块控件

发布于 2024-11-04 08:34:59 字数 131 浏览 4 评论 0原文

我想自定义滑块控件,但找不到任何可应用的东西,我想要制作的滑块应该如下图所示。请任何人建议我如何制作它....

在此处输入图像描述

I want to customize the slider control but can't find any thing to apply, the slider I want to make should be something like the following image. Please any one suggest me how can I make it....

.enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

絕版丫頭 2024-11-11 08:34:59

试试这个代码..

CGRect frame = CGRectMake(174, 12.0, 120.0, 40);
customSlider = [[UISlider alloc] initWithFrame:frame];
[customSlider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
// in case the parent view draws with a custom color or gradient, use a transparent color
customSlider.backgroundColor = [UIColor clearColor];    
UIImage *stetchLeftTrack = [[UIImage imageNamed:@"orangeslide.png"]
                            stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
UIImage *stetchRightTrack = [[UIImage imageNamed:@"yellowslide.png"]
                             stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
[customSlider setThumbImage: [UIImage imageNamed:@"slider_ball.png"] forState:UIControlStateNormal];
[customSlider setMinimumTrackImage:stetchLeftTrack forState:UIControlStateNormal];
[customSlider setMaximumTrackImage:stetchRightTrack forState:UIControlStateNormal];
customSlider.minimumValue = 0.0;
customSlider.maximumValue = 100.0;
customSlider.continuous = YES;
customSlider.value = 50.0;

// Add an accessibility label that describes the slider.
[customSlider setAccessibilityLabel:NSLocalizedString(@"CustomSlider", @"")];
[self.view addSubview:customSlider];
customSlider.tag = 1;

try this code..

CGRect frame = CGRectMake(174, 12.0, 120.0, 40);
customSlider = [[UISlider alloc] initWithFrame:frame];
[customSlider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
// in case the parent view draws with a custom color or gradient, use a transparent color
customSlider.backgroundColor = [UIColor clearColor];    
UIImage *stetchLeftTrack = [[UIImage imageNamed:@"orangeslide.png"]
                            stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
UIImage *stetchRightTrack = [[UIImage imageNamed:@"yellowslide.png"]
                             stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
[customSlider setThumbImage: [UIImage imageNamed:@"slider_ball.png"] forState:UIControlStateNormal];
[customSlider setMinimumTrackImage:stetchLeftTrack forState:UIControlStateNormal];
[customSlider setMaximumTrackImage:stetchRightTrack forState:UIControlStateNormal];
customSlider.minimumValue = 0.0;
customSlider.maximumValue = 100.0;
customSlider.continuous = YES;
customSlider.value = 50.0;

// Add an accessibility label that describes the slider.
[customSlider setAccessibilityLabel:NSLocalizedString(@"CustomSlider", @"")];
[self.view addSubview:customSlider];
customSlider.tag = 1;
深海不蓝 2024-11-11 08:34:59

试试这个

CGRect frame = *youe required frame*;
UISlider * customSlider = [[UISlider alloc] initWithFrame:frame];

// in case the parent view draws with a custom color or gradient, use a transparent color
customSlider.backgroundColor = [UIColor clearColor];    
UIImage *stetchLeftTrack = [[UIImage imageNamed:@"orangeslide.png"]
                                        stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
UIImage *stetchRightTrack = [[UIImage imageNamed:@"yellowslide.png"]
                                         stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
[customSlider setThumbImage: [UIImage imageNamed:@"slider_ball.png"] forState:UIControlStateNormal];
[customSlider setMinimumTrackImage:stetchLeftTrack forState:UIControlStateNormal];
[customSlider setMaximumTrackImage:stetchRightTrack forState:UIControlStateNormal];
customSlider.minimumValue = 0.0;
customSlider.maximumValue = 100.0;
customSlider.continuous = YES;
customSlider.value = 50.0;
[customSlider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
[self.view addSubView:customSlider];
[customSlider release];

,结果是这样的:-

根据您的要求添加图像此代码导致此滑块

Try this

CGRect frame = *youe required frame*;
UISlider * customSlider = [[UISlider alloc] initWithFrame:frame];

// in case the parent view draws with a custom color or gradient, use a transparent color
customSlider.backgroundColor = [UIColor clearColor];    
UIImage *stetchLeftTrack = [[UIImage imageNamed:@"orangeslide.png"]
                                        stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
UIImage *stetchRightTrack = [[UIImage imageNamed:@"yellowslide.png"]
                                         stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
[customSlider setThumbImage: [UIImage imageNamed:@"slider_ball.png"] forState:UIControlStateNormal];
[customSlider setMinimumTrackImage:stetchLeftTrack forState:UIControlStateNormal];
[customSlider setMaximumTrackImage:stetchRightTrack forState:UIControlStateNormal];
customSlider.minimumValue = 0.0;
customSlider.maximumValue = 100.0;
customSlider.continuous = YES;
customSlider.value = 50.0;
[customSlider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
[self.view addSubView:customSlider];
[customSlider release];

it result in this:-

add images according to your requirement this code result in this slider

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文