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的结构,我们先来看看这个结构图 --------------------------------------------- ...
随机推荐
- 数据库索引<二> 补充前篇 (上一篇抽风了,这个补上)
在前一个创建索引中已经大概说了三部分的影响,基本应该注意哪一些.写完上一篇后我感觉有很多地方没有写清楚,所以这篇就是更深入一些的理解索引到底是怎么和数据表关联,怎么快速查询的. 先看一下下面的图,图是 ...
- git在公司内部的使用实践(转)
从2011.10月左右,开始在后台组推行git版本控制,到现在也差不多半年了,也形成了一套基于git flow的副官模式工作流程: 版本定义: 版本号使用x.x.x进行定义,第一个x代表大版本只有在项 ...
- thinkjs——空对象判断
使用thinkjs来做后台的项目开发时,总免不了进行一些数据的唯一性校验,比如说:有这么一个页面,需要对钢厂的名称做一个校验,于是自己在后台做条件搜索时,一不小心用到了两种方法: 一个是find(), ...
- DOM系列---进阶篇【转】
内容提纲: 1.DOM类型 2.DOM扩展 3.DOM操作内容 一.DOM类型 DOM基础篇中,我们了解了DOM的节点并且了解怎样查询和操作节点,而本身这些不同的节点,又有着不同的类型. DOM类 ...
- 在eclipse导入项目的步骤【转】
1. Import 2. Next 3. 确定 选中copy projects into workspace Finish 这样项目就导入进来了. 4.导入jar包 Configure Bui ...
- 测试JdbcTemplate执行SQL语句和存储过程
我在项目中需要使用到oracle的语句片段和存储过程.下面就是我的测试案例: public class DbTest extends BaseTestCase { @Resource JdbcUtil ...
- C#语法小用法
数据在存为数据库之前,用JS的encodeURIComponent进行编码,现需要在后台代码中进行解码,实现decodeURIComponent的功能, 如下: HttpUtility.UrlDeco ...
- 如何使用Weave以及Docker搭建Nginx反向代理/负载均衡服务器
Hi, 今天我们将会学习如何使用 Weave 和 Docker 搭建 Nginx 的反向代理/负载均衡服务器.Weave 可以创建一个虚拟网络将 Docker 容器彼此连接在一起,支持跨主机部署及自动 ...
- PHP慢脚本日志和Mysql的慢查询日志(转)
1.PHP慢脚本日志 间歇性的502,是后端 PHP-FPM 不可用造成的,间歇性的502一般认为是由于 PHP-FPM 进程重启造成的. 在 PHP-FPM 的子进程数目超过的配置中的数量时候, ...
- [Js]JavaScript闭包和范围的快速测试
1. if (!("a" in window)) { var a = 1; } alert(a); [分析]代码含义:如果window不包含属性a,就声明一个变量a并赋值为1 ①J ...