热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

swift游乐园。创建项目级别的测试

在创建的时候选择创建后结构修改代码MyPlayground:AUIKitbasedPlaygroundforpresentinguserinterfaceimportUIKit

在创建的时候选择

 

创建后结构

修改代码

 

MyPlayground

//: A UIKit based Playground for presenting user interfaceimport UIKit
import PlaygroundSupportlet vc = ViewController1()
let navigationVc = UINavigationController(rootViewController: vc)// Present the view controller in the Live View window
PlaygroundPage.current.liveView = navigationVc;

ViewController1

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

ViewController2

import Foundation
import UIKitpublic class ViewController2:UIViewController{public override func viewDidLoad(){super.viewDidLoad()let view = UIView()view.backgroundColor = .whitelet label = UILabel()label.frame = CGRect(x: 150, y: 200, width: 200, height: 20)label.text = "Hello World!"label.textColor = .blackview.addSubview(label)self.view = view}
}

 


推荐阅读
author-avatar
s350350350
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有