您好,登錄后才能下訂單哦!
IOS學習筆記(六)之IOS開發-UISlider的概念和使用方法
Author:hmjiangqq
Email:jiangqqlmj@163.com
UISlider視圖:
作用:控制系統聲音,或者表示播放進度。
類的繼承圖如下:
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.
常用的屬性和方法如下:
我們在使用滑塊控件的時候,可以進行設置滑塊的最大值,最小值,初始值。滑塊的值的范圍為
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. p_w_picpath 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]; }
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。