如何在滑块上设置图像?

时间:2011-09-06 05:10:28

标签: iphone uislider slidetoggle

enter image description here

我想对上面的图像使用滑块控件。当用户滑动时,类别选项卡将突出显示并且全部都很高兴。那么我如何使用滑块控制器以便我可以获得此功能?如何使用滑块控件?

3 个答案:

答案 0 :(得分:0)

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.

答案 1 :(得分:0)

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

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

希望这会对你有所帮助

答案 2 :(得分:0)

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

https://github.com/samvermette/SVSegmentedControl