如何在滑块上设置图像?

发布于 2024-12-03 05:55:28 字数 143 浏览 1 评论 0原文

在此处输入图像描述

我想对上面的图像使用滑块控件。当用户滑动时,类别选项卡会突出显示并令人高兴。那么我如何使用滑块控制器才能获得此功能?如何使用滑块控件呢?

enter image description here

I want to use slider control for above image. When user slide then category tab become highlighted and all delighted. So how I use slider controller so that i can get this functionality? How use slider control for that?

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

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

发布评论

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

评论(3

蓬勃野心 2024-12-10 05:55:28
The simplest solution would be to render a UIImage behind the control to represent the track. The thumbknob can be changed with:

[mySlider setThumbImage:[UIImage imageNamed:@"thumb_image.png"] forState:UIControlStateNormal];

A side-effect of this is that the track isn't rendered unless you provide your own. This, combined with the UIImage, provide you with a custom UISlider without you having to subclass anything.
The simplest solution would be to render a UIImage behind the control to represent the track. The thumbknob can be changed with:

[mySlider setThumbImage:[UIImage imageNamed:@"thumb_image.png"] forState:UIControlStateNormal];

A side-effect of this is that the track isn't rendered unless you provide your own. This, combined with the UIImage, provide you with a custom UISlider without you having to subclass anything.
绮烟 2024-12-10 05:55:28

您显示的控件是一个分段控件,您可以使用这段代码设置图像

UISegmentedControl* offlineSegment=[[UISegmentedControl alloc] initWithItems:[[[NSMutableArray alloc] initWithObjects:@"ON",@"OFF",nil] autorelease]];
    [offlineSegment setFrame:CGRectMake(210,50,90,30)];
    offlineSegment.tintColor=[UIColor greenColor];
    offlineSegment.selectedSegmentIndex=0;

    offlineSegment.segmentedControlStyle=UISegmentedControlStyleBezeled;
    [locationSegment setImage:[UIImage imageNamed:@"onSelected.png"] forSegmentAtIndex:0];
    [locationSegment setImage:[UIImage imageNamed:@"off.png"] forSegmentAtIndex:1];
    [offlineSegment addTarget:self action:@selector(offlineSetting:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:offlineSegment];
    [offlineSegment release];

希望这对您有帮助

The control you are showing is a segment control and you can set the image by using this piece of code

UISegmentedControl* offlineSegment=[[UISegmentedControl alloc] initWithItems:[[[NSMutableArray alloc] initWithObjects:@"ON",@"OFF",nil] autorelease]];
    [offlineSegment setFrame:CGRectMake(210,50,90,30)];
    offlineSegment.tintColor=[UIColor greenColor];
    offlineSegment.selectedSegmentIndex=0;

    offlineSegment.segmentedControlStyle=UISegmentedControlStyleBezeled;
    [locationSegment setImage:[UIImage imageNamed:@"onSelected.png"] forSegmentAtIndex:0];
    [locationSegment setImage:[UIImage imageNamed:@"off.png"] forSegmentAtIndex:1];
    [offlineSegment addTarget:self action:@selector(offlineSetting:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:offlineSegment];
    [offlineSegment release];

Hope this will help you

情痴 2024-12-10 05:55:28

我不确定这是否能回答你的问题,但我看到这个 github 项目看起来有点像这样

https: //github.com/samvermette/SVSegmentedControl

I am not sure if this will answer your question or not but I have seen this project of github that looks someWhat like this

https://github.com/samvermette/SVSegmentedControl

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