工作之余,学习下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

学习网站:

http://www.helloswift.com.cn/

swift系统学习控件篇:UIProgressView+NSTimer+UIstepper+UIAlertController的更多相关文章

  1. swift系统学习控件篇:UIbutton+UIlabel+UITextField+UISwitch+UISlider

    工作之余,学习下swift大法.把自己的学习过程分享一下.当中的布局很乱,就表在意这些细节了.直接上代码: UIButton+UILabel // // ViewController.swift // ...

  2. swift系统学习控件篇:UITableView+UICollectionView

    工作之余,学习下swift大法.把自己的学习过程分享一下.当中的布局很乱,就表在意这些细节了.直接上代码: UITableView: // // ViewController.swift // UIt ...

  3. 一步一步学android之控件篇——ScrollView

    一个手机的屏幕大小是有限的,那么我要显示的东西显示不下怎么办?这就会使用到ScrollView来进行滚动显示,他的定义如下: 可以看到ScrollView是继承于FrameLayout的,所以Scro ...

  4. 用swift开发仪表盘控件(一)

    苹果swift刚刚推出不久,接触到这个语言是一个偶然的机会,无聊之余随便看了下它的语法: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveW5tYW95b2 ...

  5. DevExpress学习系列(控件篇):GridControl的基本应用

    一般属性设置 不显示分组框:Gridview->Option View->Show Group Panel=false 单元格不可编辑:gridcontrol -->gridview ...

  6. WPF学习笔记 控件篇 属性整理【1】FrameworkElement

    最近在做WPF方面的内容,由于好多属性不太了解,经常想当然的设置,经常出现自己未意料的问题,所以感觉得梳理下. ps:先补下常用控件的类结构,免得乱了 .NET Framework 4.5 Using ...

  7. openlayers4 入门开发系列之地图导航控件篇(附源码下载)

    前言 openlayers4 官网的 api 文档介绍地址 openlayers4 api,里面详细的介绍 openlayers4 各个类的介绍,还有就是在线例子:openlayers4 官网在线例子 ...

  8. 用swift开发仪表盘控件(二)

    二.代码分析 这个控件本质就是从UIView继承的一个类而已.所以整个代码事实上就是一个定制的UIView类. 依据UIView的规则进行例如以下初始化: required init(coder aD ...

  9. IOS开发之控件篇UITabBarControllor第一章 - 介绍

    UITabBarControllor的基本样子 官方有个图介绍这个TabBar的结构,我们先来看看这个结构图 --------------------------------------------- ...

随机推荐

  1. 初始maven

    Apache Maven 是一个软件项目管理和综合工具.基于项目对象模型 (POM) 的概念,Maven 可以管理一个项目的生成. 报告和文档从一块中央的信息.在JavaEE中,我们可以使用Maven ...

  2. C#.web 打开PDF

    转自:http://blog.163.com/red_guitar@126/blog/static/11720612820112483221665/ string fileName = "2 ...

  3. express+nodecoffee写passport登录验证实例(一)

    项目中要用到passport登录验证,环境如标题样:express框架,coffee模版引擎,node后台 一:建项目 直接用express命令建,虽然默认模版为jade,可以手动换成coffee哦. ...

  4. java json 的生成和解析 --json-lib

    类(java json的解析和生成): import java.util.HashMap; import java.util.Map; import net.sf.json.JSONArray; im ...

  5. div垂直居中的问题

    工作和面试时常常会遇到怎么设置div垂直居中与浏览器中:包括固定宽高和不固定宽高的 1.固定宽高的div垂直居中 宽高固定的div很容易设置让其垂直居中 <div class="cen ...

  6. 十大谷歌Google搜索技巧分享

    前言:多数人在使用Google搜索的过程是非常低效和无谓的,如果你只是输入几个关键词,然后按搜索按钮,你将是那些无法得到Google全部信息的用户,在这篇文章中,Google搜索专家迈克尔.米勒将向您 ...

  7. 利用dispatch_once创建单例

     无论是爱还是恨,你都需要单例.实际上每个iOS或Mac OS应用都至少会有UIApplication或NSApplication. 什么是单例呢?Wikipedia是如此定义的: 在软件工程中,单例 ...

  8. UVa 11427 - Expect the Expected

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  9. C++-const_cast, reinterpret_cast, static_cast的用法

    /////////////////////////////////////////////////////////////////////////////// // // FileName : cas ...

  10. vim的编码设置

    VIM的相关字符编码主要有三个参数 fencs: 它是一个编码格式的猜测列表.当用vim打开某个文件时,会依次取这里面的编码进行解码,如果某个编码格式从头至尾解码正确,那么就用那个编码 fenc:它是 ...