//
//  NativeFirstPage.swift
//  Runner
//
//  Created by admin on 2026/2/9.
//

import UIKit

class NativeFirstPage: UIViewController {
var lable:UILabel!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        view.backgroundColor = .white
        
          // 创建原生UI
          let label = UILabel()
          label.text = "iOS 原生页面."
          label.font = UIFont.systemFont(ofSize: 24, weight: .bold)
          label.textAlignment = .center
          label.translatesAutoresizingMaskIntoConstraints = false
          
          let button = UIButton(type: .custom)
          button.setTitle("点击原生按钮", for: .normal)
          button.titleLabel?.font = UIFont.systemFont(ofSize: 18)
          button.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
          button.translatesAutoresizingMaskIntoConstraints = false
        button.backgroundColor = .blue
        
          view.addSubview(label)
          view.addSubview(button)
          
          NSLayoutConstraint.activate([
              label.centerXAnchor.constraint(equalTo: view.centerXAnchor),
              label.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: -50),
              
              button.topAnchor.constraint(equalTo: label.bottomAnchor, constant: 30),
              button.centerXAnchor.constraint(equalTo: view.centerXAnchor)
          ])
        
        self.lable = label
        
    }

    @objc func buttonTapped() {
        self.lable.text = "click...";

            // 原生按钮点击事件
            let alert = UIAlertController(
                title: "原生弹窗",
                message: "来自 iOS 原生的提示",
                preferredStyle: .alert
            )
            alert.addAction(UIAlertAction(title: "确定", style: .default))
            present(alert, animated: true)
        }
    
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        view.backgroundColor = .orange
    }
    
}
