Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//
// ViewController.swift
// 010
//
// Created by chuck on 7/1/16.
// Copyright © 2016 chuck. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
super.view.backgroundColor = UIColor.cyanColor()
let myButton: UIButton = UIButton()
myButton.frame = CGRectMake(0,0,200,40)
myButton.backgroundColor = UIColor.redColor()
myButton.layer.masksToBounds = true
myButton.setTitle("UIAlertを発動", forState: UIControlState.Normal)
myButton.setTitleColor(UIColor.whiteColor(), forState:.Normal)
myButton.layer.cornerRadius = 20.0
myButton.layer.position = CGPoint(x: self.view.frame.width/2, y:200)
myButton.addTarget(self, action: "onClickMyButton:", forControlEvents: .TouchUpInside)
self.view.addSubview(myButton)
}
internal func onClickMyButton(sender: UIButton) {
let myAlert: UIAlertController = UIAlertController(title: "タイトル", message: "メッセージ", preferredStyle: .Alert)
let myOkAction = UIAlertAction(title: "OK", style: .Default) {
action in print("Action OK!!")
}
myAlert.addAction(myOkAction)
presentViewController(myAlert, animated: true, completion: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment