您的位置:首页 > 产品设计 > UI/UE

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)
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: