5 Playground
2023-02-23 本文已影响0人
为了自由的白菜
Playground
- Swift Playground首次公布与WWDC2016
- 最开始是为了让人人都能愉快的学习Swift编程
- 但发展至今,这个工具越来越强大
- iPad APP Playgrounds
创建一个Playground项目
image-20230218211234423.png简介
image-20230218211412453.png- extension -> 定义扩展
- 让打印出的数据更加可视化一些,如果没有这个,最后一句打印只能打印出一个对象
视图可视化
image-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)
}
}