UIPickerView swift
//
// ViewController.swift
// UILabelTest
//
// Created by mac on 15/6/23.
// Copyright (c) 2015年 fangyuhao. All rights reserved.
//
import UIKit
class ViewController: UIViewController,UIPickerViewDataSource,UIPickerViewDelegate {
var pickerView:UIPickerView!
override func viewDidLoad() {
super.viewDidLoad()
pickerView = UIPickerView()
pickerView.dataSource = self
pickerView.delegate = self
//设置选择框的默认值
pickerView.selectRow(1, inComponent: 0, animated: true)
pickerView.selectRow(2, inComponent: 1, animated: true)
pickerView.selectRow(3, inComponent: 2, animated: true)
self.view.addSubview(pickerView)
//建立一个按钮,触摸按钮时获得选择框被选择的索引
var button = UIButton(frame: CGRectMake(0, 0, 100, 30))
button.center = self.view.center
button.backgroundColor = UIColor.blueColor()
button.setTitle("获取信息", forState: .Normal)
button.addTarget(self, action: "getPickerViewValue", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(button)
// Do any additional setup after loading the view, typically from a nib.
}
//设置选择框的列数为3列
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 3
}
//设置选择框行数为9行
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return 9
}
//设置选择框各选项的内容,
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {
return String(row)+"-"+String(component)
}
//调整选择框的尺寸
func pickerView(pickerView: UIPickerView, widthForComponent component: Int) -> CGFloat {
if(0==component){
return 100
}else{
return 30
}
}
//检测行的选择状态
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
println(component)
println(row)
}
//触摸时,获得选中的索引
func getPickerViewValue(){
var alertView = UIAlertView()
alertView.title = "被选中的索引为"
alertView.message = String(pickerView.selectedRowInComponent(0))+"-"+String(pickerView.selectedRowInComponent(1))+"-"+String(pickerView.selectedRowInComponent(2))
alertView.addButtonWithTitle("OK")
alertView.show()
}
}
UIPickerView swift的更多相关文章
- iOS开发——UI篇Swift篇&UIPickerView
UIPickerView //返回按钮事件 @IBAction func backButtonClick() { self.navigationController?.popViewControlle ...
- Swift - 选择框(UIPickerView)的用法
1,选择框可以让用户以滑动的方式选择值.示例如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 ...
- Swift基础之UIPickerView和小animate的使用
写一个简单的UIPickerView的使用Demo,比较简单,其中和一个小动画的结合使用 UIPickerView的使用基本上跟OC语言中的一样,就是写法的样式问题,想必开发过OC的应该不需要多讲了, ...
- swift 实践- 12 -- UIPickerView
import UIKit class ViewController: UIViewController , UIPickerViewDelegate,UIPickerViewDataSource{ v ...
- swift - UIPickerView 的使用
效果显示数下图: 1.初始化 pickerView.center = self.view.center //将dataSource设置成自己 pickerView.dataSource=self // ...
- Swift学习之熟悉控件
最近是比较清闲一些的,对于一个开发者来说,这也是一个很好的充电机会.以前做项目都是使用Objective-C去开发,但我们都知道,Swift语言从2014年的出现到现在,一步一步变的完善,渐渐变的受欢 ...
- iOS - UIPickerView
前言 NS_CLASS_AVAILABLE_IOS(2_0) __TVOS_PROHIBITED @interface UIPickerView : UIView <NSCoding, UITa ...
- iOS开发——UI篇Swift篇&玩转UItableView(一)基本使用
UItableView基本使用 class ListViewController: UIViewController , UITableViewDataSource, UITableViewDeleg ...
- Swift学习之常用UI的使用
Swift学习之常用UI的使用 最近笔者在开始学习苹果最新的编程语言,因为笔者认为,苹果既然出了这门语言就绝对不会放弃,除非苹果倒闭了(当然这里知识一个玩笑). 所以在不久的将来,swift绝对是iO ...
随机推荐
- 网络设备模拟器 GNS3
https://www.gns3.com/support/docs/linux-installation sudo dpkg --add-architecture i386 sudo add-apt- ...
- 用Zend Studio12 导入在workspace中的项目
第一步: 文件(file)->新建(NEW)->其他(other) 第二步: 在打开的对话框里选择 常规(Genneral)->项目(Project) 第三步: 在打开的对话框输入项 ...
- 动态设置屏幕icon
REPORT demo_dynpro_status_icons. DATA value TYPE i VALUE 1. DATA: status_icon TYPE icons-tex ...
- PHP开发大型项目的一点经验
一.变量 最好是把所有的变量存储在一个数组中,这样在程序的开发中可以带来很多的方便,特别是当程序很大的时候.变量的命名就当适合自己的习惯,不管是用拼音还是英语,至少应当有一定的意义,以便适合记忆.变量 ...
- linux内核中的min(x, y)和max(x, y)宏定义
/linux/include/linux/kernel.h中有min(x, y)和max(x, y)的定义如下: #define min(x, y) ({ \ typeof(x) _min1 = x; ...
- Tomcat启动过程(三):从SocketProcessor到Container
1.Http11Protocol中的内部类Http11ConnectionHandler,执行其process方法 if (processor == null) { processor = creat ...
- iptables用法
iptables -t nat -A PREROUTING -s 10.10.10.0/24 -i eth1 -p tcp --dport 80 -j REDIRECT --to-ports 3128 ...
- 返回json格式时间,解析时间
传入:Json格式的时间 JS如下: yyyy-M(MM)-d(dd) H(HH):m(mm):s(ss) function timeStamp2String(time) { var data=tim ...
- Linux下mysql编译安装
一.下载安装包 因为编译安装mysql需要cmake所以先编译安装cmake,这里都一起下载下来 下载cmake,网址https://cmake.org/download/ 下载mysql,网址htt ...
- 关于js一般对象与标配对象
当一个js函数对象被创建时,Function 构造器产生的函数对象会运行类似这样的一些代码 this.prototype={constructor:this} 新函数被赋予了一个prototype属性 ...