Last active
September 26, 2016 01:23
-
-
Save banjun/82d52786e9c58c7327fb366a3acbfab2 to your computer and use it in GitHub Desktop.
UIFeedbackGenerators
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 | |
import NorthLayout | |
import Ikemen | |
class ViewController: UIViewController { | |
override func loadView() { | |
super.loadView() | |
func button(_ title: String, _ action: Selector) -> UIButton { | |
return UIButton(type: .system) ※ { | |
$0.backgroundColor = UIColor(white: 0.95, alpha: 1) | |
$0.setTitle(title, for: .normal) | |
$0.addTarget(self, action: action, for: .touchDown) | |
} | |
} | |
let autolayout = northLayoutFormat(["o": 0.5], [ | |
"n1": button("Notification 1", #selector(n1)), | |
"n2": button("Notification 2", #selector(n2)), | |
"n3": button("Notification 3", #selector(n3)), | |
"i1": button("Impact 1", #selector(i1)), | |
"i2": button("Impact 2", #selector(i2)), | |
"i3": button("Impact 3", #selector(i3)), | |
"s1": button("Selection 1", #selector(s1)), | |
]) | |
autolayout("H:|[n1]-o-[n2(==n1)]-o-[n3(==n1)]|") | |
autolayout("H:|[i1]-o-[i2(==i1)]-o-[i3(==i1)]|") | |
autolayout("H:[n1]-o-[s1(==n2)]-o-[n3]") | |
autolayout("V:[i1(==n1)]-o-[n1(==64)]-o-[s1(==n1)]|") | |
autolayout("V:[i2(==i1)]-o-[n2(==n1)]-o-[s1]") | |
autolayout("V:[i3(==i1)]-o-[n3(==n1)]-o-[s1]") | |
} | |
func n1() { | |
UINotificationFeedbackGenerator().notificationOccurred(.success) | |
} | |
func n2() { | |
UINotificationFeedbackGenerator().notificationOccurred(.warning) | |
} | |
func n3() { | |
UINotificationFeedbackGenerator().notificationOccurred(.error) | |
} | |
func i1() { | |
UIImpactFeedbackGenerator(style: .light).impactOccurred() | |
} | |
func i2() { | |
UIImpactFeedbackGenerator(style: .medium).impactOccurred() | |
} | |
func i3() { | |
UIImpactFeedbackGenerator(style: .heavy).impactOccurred() | |
} | |
func s1() { | |
UISelectionFeedbackGenerator().selectionChanged() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment