IOS學習筆記(六)之UISlider的概念和使用方法

IOS學習筆記(六)之IOS開發-UISlider的概念和使用方法

     Author:hmjiangqq

     Email:[email protected]

UISlider視圖:

作用:控制系統聲音,或者表示播放進度。

類的繼承圖如下:

SouthEast

 A UISlider object is a visual control used to select a single value from a continuous range of values. Sliders are always displayed as horizontal bars.   An indicator, or thumb, notes the current value of the slider and can be moved by the user to change the setting.

常用的屬性和方法如下:

SouthEast

我們在使用滑塊控件的時候,可以進行設置滑塊的最大值,最小值,初始值。滑塊的值的範圍爲

0.0f-1.0f之間的浮點數。值的設置方法如下:

-(void)setValue:(float)value animated:(BOOL)animated

部分屬性方法解釋如下:

@property(nonatomic) float value;                                 // default 0.0. this value will be pinned to min/max  @property(nonatomic) float minimumValue;                          // default 0.0. the current value may change if outside new min value  @property(nonatomic) float maximumValue;                          // default 1.0. the current value may change if outside new max value   @property(nonatomic,retain) UIImage *minimumValueImage;          // default is nil. image that appears to left of control (e.g. speaker off)  @property(nonatomic,retain) UIImage *maximumValueImage;     - (void)setValue:(float)value animated:(BOOL)animated; // move slider at fixed velocity (i.e. duration depends on distance). 

示例代碼如下:  


    UISlider *slider=[[UISlider alloc]initWithFrame:CGRectMake(60, 100, 200, 30)];     slider.tag=101;     //設置最大值     slider.maximumValue=1;     //設置最小值     slider.minimumValue=0;     //設置默認值     slider.value=0.8f;     //設置值(帶有動畫)     //[slider setValue:.5 animated:YES];     //添加事件     [slider addTarget:self action:@selector(valueChange:) forControlEvents:(UIControlEventValueChanged)];     [self.window addSubview:slider];     [slider release];          //[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(test:) userInfo:slider repeats:YES];          [self.window makeKeyAndVisible];     return YES; } -(void)valueChange:(UISlider *)slider{     NSLog(@"slider value : %.2f",[slider value]); }  -(void)test :(NSTimer *)timer{     UISlider *slider=timer.userInfo;     [slider setValue:0.5f animated:YES]; } 






發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章