Storyboard

2022/11/2

# 跳转传值

# 构造函数传参

# 指定内容传参

# 反向传值

# 协议传值法

# 闭包传值法

# UINavigator

# UITabBarController

  • Main创建UITabController
  • 按住controlUITabBarController拖到要关联的页面即可完成关联
  • 创建多个viewController
import UIKit

class ViewController3: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.backgroundColor = UIColor.green;
        let item = UITabBarItem(tabBarSystemItem: UITabBarItem.SystemItem.contacts, tag: 2);
        self.tabBarItem.title = "我的"; // 无效
        self.tabBarItem = item;
        self.tabBarItem.badgeValue = "99+"
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

由于是在viewDidLoad初始化的,所以初始化需要在页面首次被打开才会展示正确。书上说可以在视图控制器的构造方法中进行

# UIAlertController

import UIKit

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad();

        let button = UIButton(frame: CGRect(x: 20, y: 100, width: 100, height: 50));
        button.setTitle("出弹窗", for: UIControl.State.normal);
        button.backgroundColor = UIColor.darkGray;
        button.tintColor = UIColor.white;
        button.addTarget(self, action: #selector(alert), for: UIControl.Event.touchUpInside);
        self.view.addSubview(button);
    }
    @objc func alert() {
        // 整体的弹框
        let alertController = UIAlertController(title: "确定要点击吗?", message: "系统会崩溃哦~", preferredStyle: .alert);
        
        // 用户的选项
        let ok = UIAlertAction(title: "确定", style: UIAlertAction.Style.default) {action in
            print("点击了确定");
        }
        let cancel = UIAlertAction(title: "取消", style: UIAlertAction.Style.cancel) {action in
            print("点击了取消");
        }
        alertController.addAction(ok);
        alertController.addAction(cancel);
        self.present(alertController, animated: true);
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

# WebView

# Webkit

  • 优于webview
  • 网页与原生交互频繁的场景处理,有与javascript交互的方法。

# UIScrollCView

# UITableView

# 添加事件

  • 添加action事件,
  • @IBActionsenter需要固定
// 按钮事件
@IBAction func addItem(senter: UIButton) {
    print("aaaaa")
}
1
2
3
4
上次更新: 9/17/2024