Xcode中UISlider相關函式

2021-06-16 09:26:46 字數 1284 閱讀 4941

//左右軌的

uiimage *stetchlefttrack = [uiimage imagenamed:@"snow_bar.png"];

uiimage *stetchrighttrack = [uiimage imagenamed:@"sun_bar.png"];

//滑塊

uiimage *thumbimage = [uiimage imagenamed:@"mark.png"];

uislider *slider = [[uislider alloc] initwithframe:cgrectmake(30,320,257,7)];

slider.backgroundcolor = [uicolor clearcolor];

slider.value = 1.0;

slider.minimumvalue = 0.7;

slider.maximumvalue = 1.0;

//設定背景

[slider setminimumtrackimage:stetchlefttrack forstate:uicontrolstatenormal];

[slider setmaximumtrackimage:stetchrighttrack forstate:uicontrolstatenormal];

//注意這裡務必加上uicontrolstatehightlighted的狀態,否則當拖動滑塊時滑塊將變成原生的控制項

[slider setthumbimage:thumbimage forstate:uicontrolstatehighlighted];

[slider setthumbimage:thumbimage forstate:uicontrolstatenormal];

//滑塊拖動時的事件

[slider addtarget:self action:@selector(slidervaluechanged:) forcontrolevents:uicontroleventvaluechanged];

//滑塊拖動後的事件

[slider addtarget:self action:@selector(sliderdragup:) forcontrolevents:uicontroleventtouchupinside];

[self.view addsubview:slider];

其中繫結事件函式的返回值必須為ibaction,

- (ibaction) slidervalue:(id)sender

swift中UISlider的使用

let slider uislider frame cgrectmake 10.0,10.0,cgrectgetwidth self.view.bounds 10.0 2 20.0 self.view.addsubview slider slider.backgroundcolor uicolor....

iOS開發中UISlider的簡單使用

首先在.h檔案中宣告乙個屬性 property nonatomic,strong uislider slider 在.m檔案中初始化並設定屬性 初始化並確定frame self slider uislider alloc initwithframe cgrectmake 50,200,260,10 ...

xcode中列印毫秒時間

直接列印 nsdate date 得到的是精確到秒的時間,下面的方法可以列印精確到毫秒的時間。nsdateformatter dateformatter nsdateformatter alloc init dateformatter setdatestyle nsdateformattermedi...