IOS UISwitch 感觉官方提供的拓展性不够好,老感觉这个东西项目中用到需要自己定制
2015-11-08 20:01
603 查看
//
// ViewController.swift
// UISwitch
//
// Created by liaojianguo on 15/11/8.
// Copyright © 2015年 liaojianguo. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
var uiSwitch:UISwitch!;
override func viewDidLoad() {
super.viewDidLoad()
//uiSwitch = UISwitch()
//这个frame是没有意义的,系统的开关控件大小是确定的
uiSwitch=UISwitch(frame:CGRectMake(40,400,300,100))
//设置位置(开关大小无法设置)
uiSwitch.center=CGPointMake(100,50);
//设置默认值
uiSwitch.on=true;
uiSwitch.addTarget(self, action: Selector("switchDidChange"),
forControlEvents:UIControlEvents.ValueChanged)
self.view.addSubview(uiSwitch)
}
func switchDidChange(){
//打印当前值
print(uiSwitch.on)
if uiSwitch.on{
print("Switch is on")
//uiSwitch.setOn(true, animated:true)
}else{
print("Switch is off")
//uiSwitch.setOn(false, animated:true)
}
}
}
// ViewController.swift
// UISwitch
//
// Created by liaojianguo on 15/11/8.
// Copyright © 2015年 liaojianguo. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
var uiSwitch:UISwitch!;
override func viewDidLoad() {
super.viewDidLoad()
//uiSwitch = UISwitch()
//这个frame是没有意义的,系统的开关控件大小是确定的
uiSwitch=UISwitch(frame:CGRectMake(40,400,300,100))
//设置位置(开关大小无法设置)
uiSwitch.center=CGPointMake(100,50);
//设置默认值
uiSwitch.on=true;
uiSwitch.addTarget(self, action: Selector("switchDidChange"),
forControlEvents:UIControlEvents.ValueChanged)
self.view.addSubview(uiSwitch)
}
func switchDidChange(){
//打印当前值
print(uiSwitch.on)
if uiSwitch.on{
print("Switch is on")
//uiSwitch.setOn(true, animated:true)
}else{
print("Switch is off")
//uiSwitch.setOn(false, animated:true)
}
}
}
相关文章推荐
- UITableView 滑动自动加载更多数据
- Gson 解析 json中 value为数组
- Light OJ 1369 - Answering Queries 【规律】
- 快速排序
- Adreno Profiler GPU frequency clocks per/second
- 【2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest F】【贪心+ STL-优先队列】 Gourmet and Banquet 最大活动时间
- UIGestureRecognizer(进阶)
- UIFont中fontName大全
- iOS之UILabel显示内容自动换行
- ios开发-UIImageView的使用,点击图片刷新对应数据的过程
- 设置IIS7文件上传的最大大小 maxAllowedContentLength,maxRequestLength
- 1369 - Answering Queries
- ios开发-UISlider通过滑动添加单元格功能
- java parseint 和 Integer.value
- Arduino小车学习与研究
- This Android SDK requires Android Developer Toolkit version 23.0.0 or above
- mjpg-streamer在pcduino上的应用
- 百度编辑器ueditor获取不到内容?请把form放在table等其他元素最外面
- 关于UITableView的一点使用心得
- 什么是KVC?(What Is Key-Value Coding?)