swift系统学习控件篇:UIProgressView+NSTimer+UIstepper+UIAlertController
工作之余,学习下swift大法.把自己的学习过程分享一下.当中的布局很乱,就表在意这些细节了.直接上代码:
UIProgressView+NSTimer+UIstepper
UIStepper
UIProgressView
//
// ViewController.swift
// UIProgressView
//
// Created by shaoting on 16/3/24.
// Copyright © 2016年 9elephas. All rights reserved.
// swift控件学习篇
// UIProgressView
// NSTimer
// UIstepper
//
//
import UIKit class ViewController: UIViewController {
var button:UIButton!
var progressView:UIProgressView!
var timer:NSTimer! var stepper:UIStepper!
var label:UILabel!
override func viewDidLoad() {
super.viewDidLoad()
makeProgress() //进度条
makeStepper() //步 button = UIButton(frame: CGRect(x: self.view.frame.width/ - , y: , width: , height: ))
button.setTitle("开始", forState: UIControlState.Normal)
button.addTarget(self, action: Selector("btnOnclick"), forControlEvents: UIControlEvents.AllTouchEvents)
button.backgroundColor = UIColor.grayColor()
self.view.addSubview(button) label = UILabel(frame: CGRect(x: , y: self.view.frame.height/, width: , height: ))
label.backgroundColor = UIColor.brownColor()
label.textColor = UIColor.blackColor()
label.textAlignment = .Center
label.text = "5.0"
self.view.addSubview(label);
// Do any additional setup after loading the view, typically from a nib.
} func makeStepper(){
stepper = UIStepper(frame: CGRect(x: , y: self.view.frame.height/+, width: , height: ))
stepper.tintColor = UIColor.blueColor()
stepper.value = //默认值
stepper.minimumValue = //最小值
stepper.maximumValue = //最大值
stepper.stepValue = 1.0 //增量
stepper.autorepeat = true //设置是否允许按住不放增量
stepper.continuous = true
stepper.wraps = true //是否循环
stepper.addTarget(self, action: Selector("stepperValueChange"), forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(stepper)
}
func stepperValueChange(){
label.text = "\(stepper.value)"
} func makeProgress(){
progressView = UIProgressView(frame: CGRect(x: , y: , width: , height: ))
progressView.progressViewStyle = .Bar //类型
progressView.progress = 0.0 //初始值
progressView.progressTintColor = UIColor.blueColor() //走过进度条颜色
progressView.trackTintColor = UIColor.greenColor() //未走进度条颜色
self.view.addSubview(progressView)
}
func btnOnclick(){
button.enabled = false
timer = NSTimer.scheduledTimerWithTimeInterval(, target: self, selector:"timerAction", userInfo: nil, repeats: true)
timer.fire()
}
func timerAction(){
progressView.progress += 0.02
if progressView.progress == {
progressView.setProgress(, animated: true)
}
} override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
} }
UIAlertController
//
// ViewController.swift
// UIAlertController
//
// Created by shaoting on 16/3/25.
// Copyright © 2016年 9elephas. All rights reserved.
// swift控件学习篇
// alert //
// import UIKit class ViewController: UIViewController { var alert1:UIAlertController!
var alert2:UIAlertController!
var actionSheet:UIAlertController! var cancelAction = UIAlertAction!()
var okAction = UIAlertAction!()
var deleteAction = UIAlertAction!() override func viewDidLoad() {
super.viewDidLoad()
// 定义一个按钮,用于点击显示最简单的Alert
let button1 = UIButton(type: UIButtonType.System)
button1.frame = CGRect(x: , y: , width: , height: )
button1.setTitle("最简单的Alert", forState: UIControlState.Normal)
button1.addTarget(self, action: Selector("action1"), forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(button1)
// 定义一个按钮,用于点击显示带文本输入框的Alert
let button2:UIButton = UIButton(type: UIButtonType.System)
button2.frame = CGRect(x: , y: , width: , height: )
button2.setTitle("带文本输入框的Alert", forState: UIControlState.Normal)
button2.addTarget(self, action: Selector("action2"), forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(button2)
// 定义一个按钮,用于点击显示上拉菜单
let button3 = UIButton(type: UIButtonType.System)
button3.frame = CGRect(x: , y: , width: , height: )
button3.setTitle("上拉菜单", forState: UIControlState.Normal)
button3.addTarget(self, action: Selector("action3"), forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(button3) // Do any additional setup after loading the view, typically from a nib.
} func action1(){
//定义菜单按钮
cancelAction = UIAlertAction(title: "取消", style: UIAlertActionStyle.Cancel, handler: nil)
okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: { (UIAlertAction) -> Void in
print("you choose OK")
})
deleteAction = UIAlertAction(title: "删除", style: UIAlertActionStyle.Destructive, handler: { (UIAlertAction) -> Void in
print("you choose delete")
})
//定义一个按钮,显示带文本框的Alert
alert1 = UIAlertController(title: "最简单的Alert", message: "this is a simple", preferredStyle: UIAlertControllerStyle.Alert)
alert1.addAction(cancelAction)
alert1.addAction(okAction)
alert1.addAction(deleteAction)
self.presentViewController(alert1, animated: true, completion: nil)
}
func action2(){
alert2 = UIAlertController(title: "带输入框的alert", message: "this is a test alert", preferredStyle: UIAlertControllerStyle.Alert)
alert2.addTextFieldWithConfigurationHandler {(textFiled:UITextField!) -> Void in
textFiled.placeholder = "username"
}
alert2.addTextFieldWithConfigurationHandler { (textFiled:UITextField) -> Void in
textFiled.placeholder = "password"
textFiled.secureTextEntry = true
}
let loginAction = UIAlertAction(title: "login", style: UIAlertActionStyle.Default) { (action:UIAlertAction!) -> Void in
let name = (self.alert2.textFields?.first!)! as UITextField
let password = (self.alert2.textFields?.last)! as UITextField
print("name:\(name.text);password:\(password.text)")
}
alert2.addAction(loginAction)
self.presentViewController(alert2, animated: true, completion: nil)
}
func action3(){
actionSheet = UIAlertController(title: "上拉菜单", message: "this is a action", preferredStyle: UIAlertControllerStyle.ActionSheet)
cancelAction = UIAlertAction(title: "取消", style: UIAlertActionStyle.Cancel, handler: nil)
okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: { (UIAlertAction) -> Void in
print("you choose OK")
})
deleteAction = UIAlertAction(title: "删除", style: UIAlertActionStyle.Destructive, handler: { (UIAlertAction) -> Void in
print("you choose delete")
})
actionSheet.addAction(okAction)
actionSheet.addAction(cancelAction)
actionSheet.addAction(deleteAction)
self.presentViewController(actionSheet, animated: true, completion: nil) } override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
} }
UIProgressView+NSTimer+UIstepper源码下载:
http://download.csdn.net/detail/shaoting19910730/9471731
https://github.com/pheromone/swift-UIAlertController-
UIAlertController源码下载;
http://download.csdn.net/detail/shaoting19910730/9472635
https://github.com/pheromone/UIProgressView-NSTimer-UIstepper
学习网站:
swift系统学习控件篇:UIProgressView+NSTimer+UIstepper+UIAlertController的更多相关文章
- swift系统学习控件篇:UIbutton+UIlabel+UITextField+UISwitch+UISlider
工作之余,学习下swift大法.把自己的学习过程分享一下.当中的布局很乱,就表在意这些细节了.直接上代码: UIButton+UILabel // // ViewController.swift // ...
- swift系统学习控件篇:UITableView+UICollectionView
工作之余,学习下swift大法.把自己的学习过程分享一下.当中的布局很乱,就表在意这些细节了.直接上代码: UITableView: // // ViewController.swift // UIt ...
- 一步一步学android之控件篇——ScrollView
一个手机的屏幕大小是有限的,那么我要显示的东西显示不下怎么办?这就会使用到ScrollView来进行滚动显示,他的定义如下: 可以看到ScrollView是继承于FrameLayout的,所以Scro ...
- 用swift开发仪表盘控件(一)
苹果swift刚刚推出不久,接触到这个语言是一个偶然的机会,无聊之余随便看了下它的语法: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveW5tYW95b2 ...
- DevExpress学习系列(控件篇):GridControl的基本应用
一般属性设置 不显示分组框:Gridview->Option View->Show Group Panel=false 单元格不可编辑:gridcontrol -->gridview ...
- WPF学习笔记 控件篇 属性整理【1】FrameworkElement
最近在做WPF方面的内容,由于好多属性不太了解,经常想当然的设置,经常出现自己未意料的问题,所以感觉得梳理下. ps:先补下常用控件的类结构,免得乱了 .NET Framework 4.5 Using ...
- openlayers4 入门开发系列之地图导航控件篇(附源码下载)
前言 openlayers4 官网的 api 文档介绍地址 openlayers4 api,里面详细的介绍 openlayers4 各个类的介绍,还有就是在线例子:openlayers4 官网在线例子 ...
- 用swift开发仪表盘控件(二)
二.代码分析 这个控件本质就是从UIView继承的一个类而已.所以整个代码事实上就是一个定制的UIView类. 依据UIView的规则进行例如以下初始化: required init(coder aD ...
- IOS开发之控件篇UITabBarControllor第一章 - 介绍
UITabBarControllor的基本样子 官方有个图介绍这个TabBar的结构,我们先来看看这个结构图 --------------------------------------------- ...
随机推荐
- socket头文件
一. 三种类型的套接字:1.流式套接字(SOCKET_STREAM) 提供面向连接的可靠的数据传输服务.数据被看作是字节流,无长度限制.例如FTP协议就采用这种.2.数据报式套接字(SOCKET ...
- hdu----(5045)Contest(数位dp)
Contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
- hdu------(3549)Flow Problem(最大流(水体))
Flow Problem Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tota ...
- Uva-------(11462) Age Sort(计数排序)
B Age Sort Input: Standard Input Output: Standard Output You are given the ages (in years) of all ...
- JavaScrip的DOM操作(13号讲)
1.DOM的基本概念 DOM是文档对象模型,这种模型为树模型,文档是指标签文档:对象是指文档中每个元素:模型是指抽象化的东西 2.Windows对象操作 一.属性和方法 二.Window.open(& ...
- 网站开发中必备的8个 jQuery 效果【附源码】
jQuery 作为最优秀 JavaScript 库之一,改变了很多人编写 JavaScript 的方式.它简化了 HTML 文档遍历,事件处理,动画和 Ajax 交互,而且有成千上万的成熟 jQuer ...
- 为什么 Node.js 这么火,而同样异步模式 Python 框架 Twisted 却十几年一直不温不火?
twisted是一个强大的异步网络框架,应用的面也非常广,但是没有这几年才出现的Node.js火,社区.文档也是很少可怜我觉得二者其实在本质上差不多,而且python使用起来还是比较容易一些的 匿名用 ...
- windows系统下Tomcat与Apache服务器集成
说明:此文是看书真实试验成功的,书中提到了不同版本不兼容的问题,但是很荣幸我没碰到,此例可供参考. 本文假设你已经有了java环境和tomcat,你已经熟悉tomcat的应用. Jdk 1.7.0_5 ...
- oracle Redhat64 安装
详细可以参考:http://blog.csdn.net/chenfeng898/article/details/8782679 直接执行如下yum安装命令后,如果再出错,跳到2 yum -y inst ...
- 通过计算机名访问linux
1.安装samba 2.设置/etc/samba/smb.conf的 netbois name 配置节的值为你要设置的名称,如 netbois name = mylinux 也可以不设置此项,如果不设 ...