UISwitch swift

//
// ViewController.swift
// UILabelTest
//
// Created by mac on 15/6/23.
// Copyright (c) 2015年 fangyuhao. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
var uiswitch:UISwitch!;

override func viewDidLoad() {
    super.viewDidLoad()

    uiswitch = UISwitch()
    //设置位置
    uiswitch.center = CGPointMake(100, 50)
    //设置默认值
    uiswitch.on = true
    uiswitch.addTarget(self, action: Selector("switchDidChange"), forControlEvents: UIControlEvents.ValueChanged)

    self.view.addSubview(uiswitch)
    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
func switchDidChange(){
    println(uiswitch.on)
}

}

posted @ 2016-12-16 23:51  乱笙歌  阅读(145)  评论(0编辑  收藏  举报