Swift UIAlertController、UISegmentedControl
// MARK: 提示框
func _initAlertView() {
let btn = UIButton(type: UIButtonType.ContactAdd)
btn.frame = CGRect(x: 100, y: 150, width: 50, height: 50)
btn.addTarget(self, action: "showAlert", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(btn)
}
func showAlert() {
// let alertView = UIAlertView(title: "警告", message: "密码错误", delegate: self, cancelButtonTitle: "取消", otherButtonTitles: "确定")
//// let alertView = UIAlertView(title: "警告", message: "密码错误", delegate: self, cancelButtonTitle: "取消")
//
// //设置alertView的样式
// alertView.alertViewStyle = UIAlertViewStyle.LoginAndPasswordInput
// alertView.show()
let alertCtrl = UIAlertController(title: "温馨提示", message: "输入账号和密码", preferredStyle: UIAlertControllerStyle.Alert)
alertCtrl.addTextFieldWithConfigurationHandler { (textField) -> Void in
textField.placeholder = "输入账号"
}
alertCtrl.addTextFieldWithConfigurationHandler { (textField) -> Void in
textField.placeholder = "输入密码"
textField.secureTextEntry = true
}
let sureAction = UIAlertAction(title: "确定", style: UIAlertActionStyle.Destructive) { (alertAction) -> Void in
let tfs: [UITextField] = alertCtrl.textFields!
let tf1: UITextField = tfs[0]
let tf2: UITextField = tfs[1]
print("确定:\(alertAction.title)")
print(tf1.text)
print(tf2.text)
}
let cancelAction = UIAlertAction(title: "取消", style: UIAlertActionStyle.Destructive) { (alertAction) -> Void in
print("取消:\(alertAction.title)")
}
alertCtrl.addAction(sureAction)
alertCtrl.addAction(cancelAction)
self.presentViewController(alertCtrl, animated: true, completion: nil)
}
// MARK: 提示界面
func _initActionSheet() {
let btn = UIButton(type: UIButtonType.InfoDark)
btn.frame = CGRect(x: 200, y: 150, width: 50, height: 50)
btn.addTarget(self, action: "showActionSheet", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(btn)
}
func showActionSheet() {
// let actionSheet = UIActionSheet(title: "提示", delegate: self, cancelButtonTitle: "取消", destructiveButtonTitle: "确定", otherButtonTitles: "按钮1", "按钮2")
// actionSheet.showInView(self.view)
let alertCtrl = UIAlertController(title: "提示", message: "重点提示Message", preferredStyle: UIAlertControllerStyle.ActionSheet)
let sureAction = UIAlertAction(title: "确定", style: UIAlertActionStyle.Default) { (alertAction) -> Void in
print("确定:\(alertAction.title)")
}
let cancelAction = UIAlertAction(title: "取消", style: UIAlertActionStyle.Cancel) { (alertAction) -> Void in
print("取消:\(alertAction.title)")
}
alertCtrl.addAction(sureAction)
alertCtrl.addAction(cancelAction)
self.presentViewController(alertCtrl, animated: true, completion: nil)
}
// MARK: UISegmentedControl 两种创建方式都实用
func _initsegmentControl() {
// 1.0 设置按钮的标题数组
let array: [String] = ["选择","搜索","工具"]
// 1.1 创建分段控件
let segmentCtrl = UISegmentedControl(items: array)
segmentCtrl.frame = CGRect(x: 100, y: 100, width: 150, height: 25)
// 1.2 设置默认选中按钮
segmentCtrl.selectedSegmentIndex = 0
segmentCtrl.addTarget(self, action: "segmentAction:", forControlEvents: UIControlEvents.ValueChanged)
self.view.addSubview(segmentCtrl)
// 2.0 设置按钮的标题数组
let arrayString:[String] = ["11","22","33"];
// 2.1 创建分段控件
let segmentContrl = UISegmentedControl(items: arrayString)
segmentContrl.frame = CGRectMake(100, 200, 200, 50)
// 2.2 设置默认选中按钮
segmentContrl.selectedSegmentIndex = 2
segmentContrl.addTarget(self, action: "segmentAction:", forControlEvents: UIControlEvents.ValueChanged)
self.view.addSubview(segmentContrl)
}
func segmentAction(segment: UISegmentedControl) {
print(segment.selectedSegmentIndex)
switch segment.selectedSegmentIndex{
case 0:
print("选择")
case 1:
print("搜索")
case 2:
print("工具")
default: break
}
}
最新文章
- 《社交网络》里的评分公式——ELO排名系统
- linux shell 读取for循环中出现难处理的数据之单引号错误实例
- UVA 1252	 十五 Twenty Questions
- 泛型IComparer<;T>;排序
- wpMVVM模式绑定集合的应用
- java reflect 例子
- mysql InnoDB 索引小记
- jQuery慢慢啃之文档处理(五)
- 1_HelloWorld
- Struts2详解
- 快看我解决了一个Nginx的小问题
- Maven——settings.xml配置
- (1)Python基础
- http 连接 analysis service (ssas)
- LearnOpenGL学习笔记(六)——纹理单元
- react初始化阶段
- PAGED_CODE()
- iphone传照片还是用QQ比较好
- jQuery----操作类样式(依托开关灯案例)
- KVM资源划分分配技巧
热门文章
- static变量、static方法之间的异同
- Gift for GS5
- 生产消费模式:多线程读写队列ConcurrentQueue
- 在Extjs 的 TabPanel在 title标题栏上加按扭button
- SSM整合报错org.springframework.beans.factory.UnsatisfiedDependencyException
- js的一些编码问题
- android 命令行签名apk文件
- nyoj998——欧拉+折半查找
- influxdb和boltDB简介——MVCC+B+树,Go写成,Bolt类似于LMDB,这个被认为是在现代kye/value存储中最好的,influxdb后端存储有LevelDB换成了BoltDB
- 【hive】关于浮点数比较的问题