IOS 小贴士

拖入Switch控件 Control拖入view controller里面
在全局定义ud

    var ud:NSUserDefaults!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        ud = NSUserDefaults.standardUserDefaults()

        mySwitch.on = ud.boolForKey("showTips")

        if mySwitch.on{
            UIAlertView(title: "这里是提示", message: "今天下雨了", delegate: nil, cancelButtonTitle: "OK").show()
        }
    }
    @IBAction func change(sender: AnyObject) {
        ud.setBool(mySwitch.on, forKey: "showTips")
    }

你可能感兴趣的:(IOS 小贴士)