前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >IOS移动开发从入门到精通 视图UIView、层CALayer(2)

IOS移动开发从入门到精通 视图UIView、层CALayer(2)

作者头像
用户5760343
发布2019-07-05 11:05:16
3930
发布2019-07-05 11:05:16
举报
文章被收录于专栏:sktjsktj

1、 ViewController.swift #视图控制器

更改类的视图控制器

image.png

或者修改 rootViewController参数 2、弹出框: import UIKit class ViewController:UIViewController { var label:UILabel! override func viewDidLoad() { super.viewDidLoad() self.view.backgroundColor = UIColor.brown label = UILabel(frame:CGRect(x:40, y:100,width:240, height:44)) label.text = ”” self.view.addSubview(label) let button = UIButton(frame:CGRect(x:40, y:180,width:240, height:44)) button.setTitle(“打开新的视图控制器”, for:UIControlState()) button.backgroundColor = UIColor.black button.addTarget(self, action:#selector(ViewController.openViewController),fo:.touchUpInside) self.view.addSubview(button) } func openViewController() { let newViewController = NewViewController() newViewController.labelTxt = “传递的参数!” newViewController.viewController = self self.present(newViewController, animated:true,completion:nil) } }

3 弹出框,传递参数 import UIKit

class NewViewController:UIViewController {

var viewController:ViewController? var labelTxt = ”” override func viewDidLoad() { super.viewDidLoad() self.view.backgroundColor = UIColor.purple let label = UILabel(frame:CGRect(x:40, y:100,width:240, height:44)) label.text = labelTxt self.view.addSubview(label)

let button = UIButton(frame:CGRect(x:40, y:180,width:240, height:44)) button.setTitle(“关闭”, for:UIControlState()) button.backgroundColor = UIColor.black button.addTarget(self, action:#selector(NewViewController.dismissSelf),for:.touchUpInside) self.view.addSubview(button) }

func dismissSelf() { viewController?.label.text = “返回的参数。” self.dismiss(animated:true, completion:nil) } }

4 视图控制器周期

image.png

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019.05.28 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 更改类的视图控制器
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档