在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
import UIKit
class ViewController: UIViewController {
var uiswitch: UISwitch?
override func viewDidLoad() { super.viewDidLoad() uiswitch = UISwitch()
// 设置位置 (开关无法设置大小) uiswitch?.center = CGPoint(x: 100, y: 50) self.view.addSubview(uiswitch!)
// 设置默认值 uiswitch?.isOn = true uiswitch?.addTarget(self, action: #selector(switchDidChange), for: .valueChanged)
}
func switchDidChange(){ // 打印当前值 print(uiswitch!.isOn) }
override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. }
} |
请发表评论