2011-09-06 53 views
0

enter image description here如何在滑块上设置图像?

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

回答

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

希望这将帮助你

+0

我有这个所需的滑块。 – iRam11

+0

好,那么你需要继承UIView类,并需要在那里绘制滑块。然后你可以实现这一点,否则它不容易,不使用自定义实现 – Sabby

+0

你可以给定代码如何定制滑块和添加段控制? – iRam11