5 Playground

2023-02-23  本文已影响0人  为了自由的白菜

Playground

创建一个Playground项目

image-20230218211234423.pngimage-20230218211234423.png

简介

image-20230218211412453.pngimage-20230218211412453.png
  1. extension -> 定义扩展
    1. 让打印出的数据更加可视化一些,如果没有这个,最后一句打印只能打印出一个对象

视图可视化

image-20230218211704560.pngimage-20230218211704560.png
//ViewController1.swift

import Foundation
import UIKit

public class ViewController1: UIViewController {
    public override func viewDidLoad() {
        super.viewDidLoad()
        let button = UIButtion(type: .custom)
        button.frame = CGRect(x:0,y:200,width:300,height:50)
        button.setTitle("点击跳转",for: .normal)
        button.setTitleColor(.white, for: .normal)
        button.backgroundColor = .blue
        button.addTarget(self, action: #selector(onButtonClick),for: .touchUpInside)
        view.addSubview(button)
    }
    
    @objc func onButtonClick() {
        navigationController?.pushViewController(ViewController2(), animated: true)
    }
}
//ViewController2.swift
import Foundation
import UIKit

public class ViewController2:UIViewController {
    public override func viewDidLoad() {
        super.viewDidLoad()
        let label: UIlabel = UILabel()
        label.frame = CGRect(x:0,y:200,width:300,height:50)
        label.text = "页面2"
        label.textColor = .white
        label.backgroundColor = .red
        view.addSubview(label)
    }
}
上一篇下一篇

猜你喜欢

热点阅读