2011-08-30 71 views
2

如何在iPhone中的自定義滑塊中創建滑塊。目前我使用的「廈門國際銀行」(Interface Builder中)選擇的滑塊,但它顯示了我正常slider.But我需要滑塊與我自己的按鈕和顯示文本如何創建滑塊?

定製幻燈片來啓動

我該如何做到這一點,請幫助我。

+0

可能重複的[UISlider,滑動解鎖](http://stackoverflow.com/questions/816891/uislider-slide-to-開鎖) –

回答

0

可以完成這樣

UISlider *mySlider; 
mySlider = [[UISlider alloc]init]; 
/* Slider Customization */ 
[mySlider setThumbImage:[UIImage imageNamed:@"yourimage.png"] forState:UIControlStateNormal]; 
/*the above line will sets a custom image for your slider ball i.e; thumb image*/ 

/* the below code will make your slider line custom */ 
UIImage *sliderLeftTrackImage = [[UIImage imageNamed: @"lineImage.png"] stretchableImageWithLeftCapWidth: 9 topCapHeight: 0]; 
UIImage *sliderRightTrackImage = [[UIImage imageNamed: @"lineImage.png"] stretchableImageWithLeftCapWidth: 9 topCapHeight: 0]; 

[mySlider setMinimumTrackImage: sliderLeftTrackImage forState: UIControlStateNormal]; 
[mySlider setMaximumTrackImage: sliderRightTrackImage forState: UIControlStateNormal]; 
/* end of Slider Customization */ 
[mySlider release]; 
0

您將需要使用可拉伸的圖像進行定製,並用以下方法加載它們:

setMinimumTrackImage:forState: 
setMaximumTrackImage:forState: 
setThumbImage:forState: 

最小的軌跡圖像是左邊的部分的拇指(默認爲藍色),最大的軌道圖像在右側。

下面是定製爲例:

UIImage *minimumTrackImage = [UIImage imageNamed:@"sliderMin.png"]; 
UIImage *stretchableMinimumTrackImage = [minimumTrackImage stretchableImageWithLeftCapWidth:6 topCapHeight:6]; 
[slider setMinimumTrackImage:stretchableMinimumTrackImage forState:UIControlStateNormal]; 

UIImage *maximumTrackImage = [UIImage imageNamed:@"sliderMax.png"]; 
UIImage *stretchableMaximumTrackImage = [maximumTrackImage stretchableImageWithLeftCapWidth:6 topCapHeight:6]; 
[slider setMaximumTrackImage:stretchableMaximumTrackImage forState:UIControlStateNormal]; 

UIImage *handle = [UIImage imageNamed:@"sliderHandle.png"]; 

[slider setThumbImage:handle forState:UIControlStateNormal]; 
0
UISlider *objslider = [[UISlider alloc] initWithFrame:CGRectMake(14, 249, 290, 22)]; 

UIImage *stetchLeftTrack = [[UIImage imageNamed:@"slider_fill.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:0.0]; 

UIImage *stetchRightTrack = [[UIImage imageNamed:@"slider.png"] 
           stretchableImageWithLeftCapWidth:0.0 topCapHeight:0.0]; 

[objslider setThumbImage: [UIImage imageNamed:@"slider_ball.png"]forState:UIControlStateNormal]; 

[objslider setMinimumTrackImage:stetchLeftTrack forState:UIControlStateNormal]; 

[objslider setMaximumTrackImage:stetchRightTrack forState:UIControlStateNormal]; 

objslider.minimumValue = 0.0; 

objslider.maximumValue = 100.0; 

objslider.continuous = YES; 

objslider.value = 0.0; 

[self.view addSubview:objslider];