美文网首页
Playground 可视化开发

Playground 可视化开发

作者: gaookey | 来源:发表于2020-09-12 22:31 被阅读0次

    我们只需要将想要显示的 UIView 子类赋值给当前 PlaygroundPageliveView 属性,并且打开 Assistant Editor (Alt + Shift + Command + Return),就能看到我们创建的视图了

    import UIKit
    import PlaygroundSupport
    
    let label = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 100))
    label.backgroundColor = .cyan
    label.font = UIFont.systemFont(ofSize: 35)
    label.textAlignment = .center
    label.text = "Hello World"
    label.layer.masksToBounds = true
    label.layer.cornerRadius = 20
    PlaygroundPage.current.liveView = label
    
    
    image.png
    ----------
    import UIKit
    import PlaygroundSupport
    
    class ViewController: UITableViewController {
        override func viewDidLoad() {
            super.viewDidLoad()
            view.backgroundColor = .cyan
        }
    }
    
    extension ViewController {
        override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            return 30
        }
        
        override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            let cell = UITableViewCell()
            cell.textLabel?.text = String(indexPath.row)
            return cell
        }
    }
    
    extension ViewController {
        override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
            print("Select: \(indexPath.row)")
        }
    }
    
    let vc = ViewController()
    PlaygroundPage.current.liveView = vc
    

    相关文章

      网友评论

          本文标题:Playground 可视化开发

          本文链接:https://www.haomeiwen.com/subject/ctugektx.html