您好,登錄后才能下訂單哦!
IOS學(xué)習(xí)筆記(六)之IOS開發(fā)-UISlider的概念和使用方法
Author:hmjiangqq
Email:jiangqqlmj@163.com
UISlider視圖:
作用:控制系統(tǒng)聲音,或者表示播放進(jìn)度。
類的繼承圖如下:
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.
常用的屬性和方法如下:
我們?cè)谑褂没瑝K控件的時(shí)候,可以進(jìn)行設(shè)置滑塊的最大值,最小值,初始值。滑塊的值的范圍為
0.0f-1.0f之間的浮點(diǎn)數(shù)。值的設(shè)置方法如下:
-(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; //設(shè)置最大值 slider.maximumValue=1; //設(shè)置最小值 slider.minimumValue=0; //設(shè)置默認(rèn)值 slider.value=0.8f; //設(shè)置值(帶有動(dòng)畫) //[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]; }
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。