Swift UISwitch/UIProgressView/UISlider
来源:互联网 发布:tik江苏泰微课网络课程 编辑:程序博客网 时间:2024/05/18 20:49
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, 200, 200, 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时,值改变事件就无效.
三个控件的效果图:
0 0
- Swift UISwitch/UIProgressView/UISlider
- UISwitch,UISlider,UIProgressView,UIActivityIndicatorView
- UIProgressView/UISlider / UISwitch 简单使用
- UISlider/UISegmentedControl/UISetpper/UISwitch/UIProgressView/UIPageControl
- UISlider/UISegmentedControl/UISetpper/UISwitch/UIProgressView/UIPageControl/UIImageView
- UISlider、UIStepper、UISegmentControl、UISwitch、UIProgressView、UIActivityIndicatorView
- swift UIProgressView UISilder UISwitch使用
- swift UIProgressView UISilder UISwitch使用
- UIActionSheet,UIAlertView,UISlider,UIProgressView,UISwitch,UISegmentControl,UIActivityIndicatorView基
- UI控件笔记(八):UI之UISlider\UIStepper\ UIProgressView\ UITextView\UISwitch\ UIActivityIndicatorView\ UISeg
- IOS7UISlider/UIProgressView/UISwitch/UISegmentedControl
- UIProgressView和UISlider
- UISlider和UIProgressView
- UISlider与UISwitch控件
- UISlider与UISwitch控件
- UISegmentedControll,UISlider,UISwitch,UIStepper
- UISegmentedControl、UISwitch、UISlider
- UIswitch UISlider(基础篇)
- 关于TP的模型中一次return多个数组的解决方法:
- Github源码推荐:(01.04):iOS开发蓝牙,启动动画,自定义Tabbar
- oracle 存储过程的基本语法
- variadic templates sample code
- 牛津大学视觉几何组VGG卷积神经网络实践教程VGG Convolutional Neural Networks Practical
- Swift UISwitch/UIProgressView/UISlider
- Linux _pthread 线程的同步 浅见
- 翻译mos文章禁用透明大页
- git 使用帮助
- OpenStack让数据中心随时就绪
- Android 之打造仿微信页面切换公共方法及实现
- 【设计谈】字体与排版
- win7系统下装ubantu
- 【matlab】:matlab实现求图像中的多个质心