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的结构,我们先来看看这个结构图 --------------------------------------------- ...
随机推荐
- es根据磁盘使用情况来决定是否分配shard
注意两个地方说法有出入,待实测! es可以根据磁盘使用情况来决定是否继续分配shard.默认设置是开启的,也可以通过api关闭:cluster.routing.allocation.disk.thre ...
- smartGit30天试用过期
Windows: %APPDATA%\syntevo\SmartGit\OS X: ~/Library/Preferences/SmartGit/Unix/Linux: ~/.smartgit ...
- vim多行注释和取消多行注释
多行注释: 1. 进入命令行模式,按ctrl + v进入 visual block模式(可视快模式),然后按j, 或者k选中多行,把需要注释的行标记起来 2. 按大写字母i,再插入注释符,例如// 3 ...
- PHP获取汉字的转化为拼音字母实现程序
一个完整的php获取汉字拼音字母的实现程序,有需要的朋友可参考一下. <?php class GetPingYing { private $pylist = array( 'a'=>-20 ...
- Xcode连接git@osc
Xcode 已经集成了git,建立新项目时钩选使用git,然后按照下面步骤让Xcode和git@osc 建立连接. 第一步:成生SSH密钥 打开终端命令工具,输入命令:ssh-keygen -t rs ...
- Google十大惊人产品
国外资讯网站BusinessInsider刊文细数了谷歌惊世骇俗的十大产品,范围从无人驾驶汽车到太空电梯再到高空风力发电,每一项都令人无限神往,充满未来感. 以下是谷歌十大惊人产品: 众所周知,谷歌并 ...
- poj题目必做
OJ上的一些水题(可用来练手和增加自信) (poj3299T,poj2159T,poj2739T,poj1083T,poj2262T,poj1503T,poj3006T,poj2255T,poj309 ...
- for循环语句示例应用
age = 22 #优化前 ''' for i in range(10): guess_num = int(input('input your guess num:')) if guess_num = ...
- select2去除搜索框
$("#type_select").select2({ minimumResultsForSearch: -1 });
- uboot启动内核(3)
nand read.jffs2 0x30007FC0 kernel; 从NAND读出内核:从哪读,从kernel分区 放到哪去 -0x30007FC0 nand read.jffs2 0x3000 ...