Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
//
// ViewController.swift
// 1-2
//
// Created by Takashi Yoneyama on 6/23/16.
// Copyright © 2016 Takashi Yoneyama. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
private var myInfoDarkButton: UIButton!
private var myInfoLightButton: UIButton!
private var myAddButton: UIButton!
private var myDetailButton: UIButton!
private var mySystemButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// ボタン生成
myInfoDarkButton = UIButton(type: UIButtonType.InfoDark)
myInfoLightButton = UIButton(type: UIButtonType.InfoLight)
myAddButton = UIButton(type: UIButtonType.ContactAdd)
myDetailButton = UIButton(type: UIButtonType.DetailDisclosure)
mySystemButton = UIButton(type: UIButtonType.System)
// ボタンの位置を指定する
myInfoDarkButton.layer.position = CGPoint(x: self.view.frame.width/2, y:50)
myInfoLightButton.layer.position = CGPoint(x: self.view.frame.width/2, y:100)
myAddButton.layer.position = CGPoint(x: self.view.frame.width/2, y:150)
myDetailButton.layer.position = CGPoint(x: self.view.frame.width/2, y:200)
// ボタンに枠を設定
mySystemButton.frame = CGRectMake(0,0,200,50)
mySystemButton.layer.position = CGPoint(x: self.view.frame.width/2, y:250)
// ボタンに文言追加
mySystemButton.setTitle("mySystemButton", forState: UIControlState.Normal)
// タグ設定
myInfoDarkButton.tag = 1
myInfoLightButton.tag = 2
myAddButton.tag = 3
myDetailButton.tag = 4
mySystemButton.tag = 5
// イベントを追加
myInfoDarkButton.addTarget(self, action: "onClickMyButton:", forControlEvents: .TouchUpInside)
myInfoLightButton.addTarget(self, action: "onClickMyButton:", forControlEvents: .TouchUpInside)
myAddButton.addTarget(self, action: "onClickMyButton:", forControlEvents: .TouchUpInside)
myDetailButton.addTarget(self, action: "onClickMyButton:", forControlEvents: .TouchUpInside)
mySystemButton.addTarget(self, action: "onClickMyButton:", forControlEvents: .TouchUpInside)
self.view.addSubview(myInfoDarkButton)
self.view.addSubview(myInfoLightButton)
self.view.addSubview(myAddButton)
self.view.addSubview(myDetailButton)
self.view.addSubview(mySystemButton)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
internal func onClickMyButton(sender: UIButton) {
print("onClickMyButton")
print("sender.currentTitle: \(sender.currentTitle)")
print("sender.tag: \(sender.tag)")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment