2011-09-06 169 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