-
-
Save akio0911/cd2e3077e7ad68872705 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class ViewController: UIViewController { | |
@IBOutlet weak var target1TextField: UITextField! | |
@IBOutlet weak var target2TextField: UITextField! | |
@IBOutlet weak var target1Label: UILabel! | |
@IBOutlet weak var target2Label: UILabel! | |
@IBOutlet weak var target1Switch: UISwitch! | |
@IBOutlet weak var target2Switch: UISwitch! | |
// 計算結果 | |
@IBOutlet weak var resultLabel: UILabel! | |
@IBOutlet var tapGesture: UITapGestureRecognizer! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// ジェスチャー追加 | |
self.view.addGestureRecognizer(self.tapGesture) | |
} | |
// 計算処理 | |
@IBAction func calculate(sender: AnyObject) { | |
let target1Num = (self.target1TextField.text as NSString).integerValue | |
let target2Num = (self.target2TextField.text as NSString).integerValue | |
let target1 = self.target1Switch.on ? -target1Num : target1Num | |
let target2 = self.target2Switch.on ? -target2Num : target2Num | |
self.target1Label.text = "\(target1)" | |
self.target2Label.text = "\(target2)" | |
self.resultLabel.text = "\(target1 + target2)" | |
} | |
// キーボード外をタップしてナンバーパッドを閉じる | |
@IBAction func closeNumberPad(sender: UITapGestureRecognizer) { | |
self.view.endEditing(true) | |
} | |
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