【Swift3】UIAlertController의 샘플 3선
17612 단어 iOSSwiftSwift3.0UIAlertController
alert
데모
코드
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func showAlert(_ sender: Any) {
let alert = UIAlertController(title:"タイトル", message: "メッセージ", preferredStyle: UIAlertControllerStyle.alert)
let action1 = UIAlertAction(title: "アクション1", style: UIAlertActionStyle.default, handler: {
(action: UIAlertAction!) in
print("アクション1をタップした時の処理")
})
let action2 = UIAlertAction(title: "アクション2", style: UIAlertActionStyle.default, handler: {
(action: UIAlertAction!) in
print("アクション2をタップした時の処理")
})
let action3 = UIAlertAction(title: "アクション3", style: UIAlertActionStyle.destructive, handler: {
(action: UIAlertAction!) in
print("アクション3をタップした時の処理")
})
let cancel = UIAlertAction(title: "キャンセル", style: UIAlertActionStyle.cancel, handler: {
(action: UIAlertAction!) in
print("キャンセルをタップした時の処理")
})
alert.addAction(action1)
alert.addAction(action2)
alert.addAction(action3)
alert.addAction(cancel)
self.present(alert, animated: true, completion: nil)
}
}
actionSheet
데모
코드
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func showAlert(_ sender: Any) {
let actionSheet = UIAlertController(title: "タイトル", message: "メッセージ", preferredStyle: UIAlertControllerStyle.actionSheet)
let action1 = UIAlertAction(title: "アクション1", style: UIAlertActionStyle.default, handler: {
(action: UIAlertAction!) in
print("アクション1をタップした時の処理")
})
let action2 = UIAlertAction(title: "アクション2", style: UIAlertActionStyle.default, handler: {
(action: UIAlertAction!) in
print("アクション2をタップした時の処理")
})
let action3 = UIAlertAction(title: "アクション3", style: UIAlertActionStyle.destructive, handler: {
(action: UIAlertAction!) in
print("アクション3をタップした時の処理")
})
let cancel = UIAlertAction(title: "キャンセル", style: UIAlertActionStyle.cancel, handler: {
(action: UIAlertAction!) in
print("キャンセルをタップした時の処理")
})
actionSheet.addAction(action1)
actionSheet.addAction(action2)
actionSheet.addAction(action3)
actionSheet.addAction(cancel)
self.present(actionSheet, animated: true, completion: nil)
}
}
action을 동적으로 생성하는 방법
코드
import UIKit
class ViewController: UIViewController {
var yamaguchiMaho: [String] = []
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func showAlert(_ sender: Any) {
let alert = UIAlertController(title:"山口真帆", message: "例の動画", preferredStyle: UIAlertControllerStyle.alert)
yamaguchiMaho = ["ハレンチ", "写真集", "ナマ配信"]
for harenchi in yamaguchiMaho {
let harenchi = UIAlertAction(title: harenchi, style: UIAlertActionStyle.default, handler: {
(action: UIAlertAction!) in
print(harenchi)
})
alert.addAction(harenchi)
}
let cancel = UIAlertAction(title: "キャンセル", style: UIAlertActionStyle.cancel, handler: {
(action: UIAlertAction!) in
print("キャンセルをタップした時の処理")
})
alert.addAction(cancel)
self.present(alert, animated: true, completion: nil)
}
}
Reference
이 문제에 관하여(【Swift3】UIAlertController의 샘플 3선), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/Simmon/items/319b738e2a667d6a6b3d
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func showAlert(_ sender: Any) {
let alert = UIAlertController(title:"タイトル", message: "メッセージ", preferredStyle: UIAlertControllerStyle.alert)
let action1 = UIAlertAction(title: "アクション1", style: UIAlertActionStyle.default, handler: {
(action: UIAlertAction!) in
print("アクション1をタップした時の処理")
})
let action2 = UIAlertAction(title: "アクション2", style: UIAlertActionStyle.default, handler: {
(action: UIAlertAction!) in
print("アクション2をタップした時の処理")
})
let action3 = UIAlertAction(title: "アクション3", style: UIAlertActionStyle.destructive, handler: {
(action: UIAlertAction!) in
print("アクション3をタップした時の処理")
})
let cancel = UIAlertAction(title: "キャンセル", style: UIAlertActionStyle.cancel, handler: {
(action: UIAlertAction!) in
print("キャンセルをタップした時の処理")
})
alert.addAction(action1)
alert.addAction(action2)
alert.addAction(action3)
alert.addAction(cancel)
self.present(alert, animated: true, completion: nil)
}
}
데모
코드
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func showAlert(_ sender: Any) {
let actionSheet = UIAlertController(title: "タイトル", message: "メッセージ", preferredStyle: UIAlertControllerStyle.actionSheet)
let action1 = UIAlertAction(title: "アクション1", style: UIAlertActionStyle.default, handler: {
(action: UIAlertAction!) in
print("アクション1をタップした時の処理")
})
let action2 = UIAlertAction(title: "アクション2", style: UIAlertActionStyle.default, handler: {
(action: UIAlertAction!) in
print("アクション2をタップした時の処理")
})
let action3 = UIAlertAction(title: "アクション3", style: UIAlertActionStyle.destructive, handler: {
(action: UIAlertAction!) in
print("アクション3をタップした時の処理")
})
let cancel = UIAlertAction(title: "キャンセル", style: UIAlertActionStyle.cancel, handler: {
(action: UIAlertAction!) in
print("キャンセルをタップした時の処理")
})
actionSheet.addAction(action1)
actionSheet.addAction(action2)
actionSheet.addAction(action3)
actionSheet.addAction(cancel)
self.present(actionSheet, animated: true, completion: nil)
}
}
action을 동적으로 생성하는 방법
코드
import UIKit
class ViewController: UIViewController {
var yamaguchiMaho: [String] = []
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func showAlert(_ sender: Any) {
let alert = UIAlertController(title:"山口真帆", message: "例の動画", preferredStyle: UIAlertControllerStyle.alert)
yamaguchiMaho = ["ハレンチ", "写真集", "ナマ配信"]
for harenchi in yamaguchiMaho {
let harenchi = UIAlertAction(title: harenchi, style: UIAlertActionStyle.default, handler: {
(action: UIAlertAction!) in
print(harenchi)
})
alert.addAction(harenchi)
}
let cancel = UIAlertAction(title: "キャンセル", style: UIAlertActionStyle.cancel, handler: {
(action: UIAlertAction!) in
print("キャンセルをタップした時の処理")
})
alert.addAction(cancel)
self.present(alert, animated: true, completion: nil)
}
}
Reference
이 문제에 관하여(【Swift3】UIAlertController의 샘플 3선), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/Simmon/items/319b738e2a667d6a6b3d
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
import UIKit
class ViewController: UIViewController {
var yamaguchiMaho: [String] = []
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func showAlert(_ sender: Any) {
let alert = UIAlertController(title:"山口真帆", message: "例の動画", preferredStyle: UIAlertControllerStyle.alert)
yamaguchiMaho = ["ハレンチ", "写真集", "ナマ配信"]
for harenchi in yamaguchiMaho {
let harenchi = UIAlertAction(title: harenchi, style: UIAlertActionStyle.default, handler: {
(action: UIAlertAction!) in
print(harenchi)
})
alert.addAction(harenchi)
}
let cancel = UIAlertAction(title: "キャンセル", style: UIAlertActionStyle.cancel, handler: {
(action: UIAlertAction!) in
print("キャンセルをタップした時の処理")
})
alert.addAction(cancel)
self.present(alert, animated: true, completion: nil)
}
}
Reference
이 문제에 관하여(【Swift3】UIAlertController의 샘플 3선), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/Simmon/items/319b738e2a667d6a6b3d텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)