- iOS (Swift)hailiangwang.com
对于iOS,你可以使用Swift和Xcode来开发。这里是一个简单的Swift示例,创建一个按钮点击后显示警告框的视图控制器。
swift
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// 创建一个按钮
let myButton = UIButton(type: .system)
myButton.setTitle("点击我", for: .normal)
myButton.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
myButton.center = view.center
myButton.frame = CGRect(origin: CGPoint(x: 0, y: 0), size: CGSize(width: 200, height: 50))
view.addSubview(myButton)
}
@objc func buttonTapped() {
let alert = UIAlertController(title: "警告", message: "你点击了按钮!", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "确定", style