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 ...
随机推荐
- Anaconda日志
https://fedoraproject.org/wiki/Anaconda/Logging Anaconda日志 centos7 anaconda安装日志目录 /var/log/anaconda ...
- 跨域请求之JSONP 二
续上篇,加两个实用功能 1,增加data属性,请求参数2,增加scope属性,可以让回调函数在指定的上下文中执行 接口如下 1 2 3 4 5 6 Sjax.load(url, { data ...
- LiveView 0.8 RC1 could boot evidence files acquired from Win10 64bit
The latest Windows 10 will be more and more popular in the very near future. Now let's take a look i ...
- Sunglasses
It's hot this summer. It also reminds me of one case about sunglasses. She was new to this company a ...
- VMware NAT模式 Cent OS IP配置
1:首先VMware 桥接模式 CentOS ip 配置,关键点,ip的网关和DNS1设置成宿主机的网关和DNS 原理:桥接的模式就是通过物理网卡实现的. 2:以图展示VMware NAT模式 Cen ...
- MySQL允许远程访问
grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option; flush privileges; ...
- js设计模式(12)---职责链模式
0.前言 老实讲,看设计模式真得很痛苦,一则阅读过的代码太少:二则从来或者从没意识到使用过这些东西.所以我采用了看书(<js设计模式>)和阅读博客(大叔.alloyteam.聂微东)相结合 ...
- 在Linux命令行窗口中,怎么向上翻页?
解决方法:本机环境:vmware linux Redhat9.0版本 使用:Shift + PageUp 和 Shift + PageDown向上和向下翻页
- 将List<T>转化成 DataTable--调整可空类型的转化错误
加载表结构并保持成XML string cmdText = @"select * from kb_lable_temp where 1=2"; using (SqlConnecti ...
- c# 加密/解密 哈希
DES一共就有4个参数参与运作:明文.密文.密钥.向量.其中这4者的关系可以理解为: 密文=明文+密钥+向量: 明文=密文-密钥-向量: 为什么要向量这个参数呢?因为如果有一篇文章,有几个词重复,那么 ...