Swift UISwitchUIProgressViewUISlider

Swift UISwitchUIProgressViewUISlider,第1张

概述1.UISwitch 开关视图,可以让用户快速的开关一个功能,比如蓝牙,wif等. 系统默认样式: 上面绿色的开启状态,下面的是关闭状态. UISwitch的构成部分: //MARK: initSwitchView var coun : NSInteger = 0 func initSwitchView() { let testSwitch = UISwitch.i

1.UISwitch

开关视图,可以让用户快速的开关一个功能,比如蓝牙,wif等.

系统默认样式:

上面绿色的开启状态,下面的是关闭状态.

UISwitch的构成部分:


//MARK: initSwitchVIEw    var coun : NSInteger = 0    func initSwitchVIEw() {        let testSwitch = UISwitch.init(frame: CGRectMake(100,100,51,31))        self.vIEw.addSubvIEw(testSwitch)                //        testSwitch.on = true  // 设置开关状态        //        testSwitch.onTintcolor = UIcolor.redcolor()        testSwitch.tintcolor = UIcolor.bluecolor()        testSwitch.thumbTintcolor = UIcolor.redcolor()        testSwitch.seton(true,animated: true) // 设置动画                        testSwitch.addTarget(self,action: #selector(VIEwController.UISwitchValueChange),forControlEvents:UIControlEvents.ValueChanged)    }//MARK: UISwitchValueChange 事件    func UISwitchValueChange() {        self.coun = self.coun + 1        print("\(self.coun)")    }
UISwitch的大小是W51H31,这固定在,在设置它的frame的时候可以不设置其大小.为什么是固定的呢?我们可以在IB里面看看就知道了.

拖一个控件在IB中,我们看看


这个控件比较简单,一般使用系统样式就可以了,主要是增加值改变事件.

2.UIProgressVIEw

UIProgressVIEw进度条样式.默认最小值是0,最大值是0且不可以改变.

UIProgressVIEw的构成部分:


UIProgressVIEw的样式:


UIProgressVIEw的高度也是固定的,固定值是2.

//MARK: initProcessVIEw    func initProcessVIEw() {        let testProcessVIEw = UIProgressVIEw.init(frame: CGRectMake(60,150,200,2))        self.vIEw.addSubvIEw(testProcessVIEw)                testProcessVIEw.tag = 1;//        testProcessVIEw.progress = 0.8//        testProcessVIEw.progressImage = UIImage.init(named: "1")//        testProcessVIEw.progresstintcolor = UIcolor.redcolor()//        testProcessVIEw.trackTintcolor = UIcolor.greencolor()//        testProcessVIEw.trackImage = UIImage.init(named: "2")//        testProcessVIEw.progressVIEwStyle = .bar  //样式                NSTimer.scheduledTimerWithTimeInterval(1,target: self,selector: #selector(VIEwController.UIProgressVIEwvalueChange),userInfo: nil,repeats: true)    }//MARK: UIProgressVIEwvalueChange 事件    func UIProgressVIEwvalueChange() {        let testProcessVIEw = self.vIEw.vIEwWithTag(1) as! UIProgressVIEw        if testProcessVIEw.progress == 1 {            testProcessVIEw.progress = 0        }        testProcessVIEw.progress = testProcessVIEw.progress + 0.05    }
3.UiSlider

UiSlider感觉就是在UIProgressVIEw的上面增加了一个用户可以手动控制的按钮,且最大值和最小值都可以由用户自行设置.

UiSlider的构成:

UiSlider的高度默认是31,我们看看UISwitch就知道了,它们有点联系了.

//MARK: initSlIDerVIEw    func initSlIDerVIEw() {        let testSlIDer = UiSlider.init(frame: CGRectMake(60,31))        self.vIEw.addSubvIEw(testSlIDer)                testSlIDer.minimumValue = 0    //设置最小值        testSlIDer.maximumValue = 100  //设置最大值//        testSlIDer.value = 10          //设置当前值        testSlIDer.setValue(20,animated: true) // 设置当前值 是否加动画效果        testSlIDer.continuous = true        testSlIDer.minimumValueImage = UIImage.init(named: "1")        testSlIDer.maximumValueImage = UIImage.init(named: "2")        testSlIDer.thumbTintcolor = UIcolor.redcolor()        testSlIDer.addTarget(self,action: #selector(VIEwController.UiSliderValueChage),forControlEvents: UIControlEvents.ValueChanged)    }//MARK: UiSliderValueChage 事件    func UiSliderValueChage(testSlIDer : UiSlider) {        print("\(testSlIDer.value)")    }
UiSlider的continuous属性默认是true,这样当它的值改变的时候,值改变事件就可以关联起来,设置为false时,值改变事件就无效.
三个控件的效果图:

总结

以上是内存溢出为你收集整理的Swift UISwitch/UIProgressView/UISlider全部内容,希望文章能够帮你解决Swift UISwitch/UIProgressView/UISlider所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1078124.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存