当前位置:网站首页>Xcode 建立 UIKit 项目(Hello World)
Xcode 建立 UIKit 项目(Hello World)
2022-07-30 05:43:00 【大头鑫】
新建 StoryBoard 项目
新建工程 File>New>Project

选择 App 然后 next
写下自己的项目名,这里我写 Test

界面选择 StoryBoard
StoryBoard 与 controller 的绑定
Main.storyboard 的 View Controller 可以填写自定义的 title

将这个 View Controller 绑定到自己定义的 ViewController 类

与这里的 .swift 文件对应

配置解读
info.plist 文件存放一想工程配置,如下图。
- Delegate Name 是放代理的名字,这里它默认为:*$(PRODUCT_MODULE_NAME).SceneDelegate,*与左侧的 SceneDelegate 对应。SceneDelegate 用于处理与 UI 相关的内容。
- StoryBoard Name 存放主要故事板名字,它默认为 Main ,与左侧的 Main.storyboard 文件对应。

使用 UIKit 增加一个按钮
在 ViewController 的重载函数 viewDidLoad 中添加一个按钮,这种 #selector 的形式要使用 Object-C 的函数调用。
let confirm = UIButton(frame: CGRect(x: 10, y: 40, width: 100, height: 40))
confirm.backgroundColor = .green
confirm.setTitle("He", for: .normal)
confirm.setTitleColor(.white, for: .normal)
confirm.addTarget(self, action: #selector(ViewController.press), for: .touchUpInside)
self.view.addSubview(confirm)
在 ViewController 中添加一个 objc 的函数,作为按钮的点击响应事件。
@objc func press() {
let alertController = UIAlertController()
alertController.title = "OK"
alertController.message = "Hello World!!"
let cancelAction = UIAlertAction(title: "No", style: .cancel)
let confirmAction = UIAlertAction(title: "Yes", style: .default)
alertController.addAction(cancelAction)
alertController.addAction(confirmAction)
self.present(alertController, animated: true, completion: nil)
}
运行结果

边栏推荐
- TDengine cluster construction
- TDengine集群搭建
- [MATLAB] Image Processing - Recognition of Traffic Signs
- vulnhub-XXE ctf security question
- c#下Web3合约空投、转账调用代码
- Using PyQt5 to add an interface to YoloV5 (1)
- The number of warehouse 】 data quality
- 【OS】操作系统高频面试题英文版(1)
- Kotlin协程的简单用法:1、GlobalScope(不建议使用);2、lifecycleScope、viewModelScope(建议使用);
- Function 函数式接口及应用
猜你喜欢

第一个WebAssembly程序

【MySQL功法】第5话 · SQL单表查询

MySQL - Function and Constraint Commands
Awd summary

MySQL achievement method 】 【 5 words, single table SQL queries
Remember a traffic analysis practice - Anheng Technology (August ctf)

【数仓】数据仓库高频面试题题英文版(1)

uni-app: The use of uni-icons and how to customize icons

Detailed explanation of regular expression syntax and practical examples

Understand JDBC in one article
随机推荐
十八、Kotlin进阶学习:1、挂起函数执行的顺序;2、使用 async 和 await 异步执行挂起函数;3、协程的调度器;4、父子协程;
Calendar类的习题
MySQL 5.7 安装教程(全步骤、保姆级教程)
Detailed explanation of ClickHouse query statement
Servlet基本原理与常见API方法的应用
使用PyQt5为YoloV5添加界面(一)
MySQL - 函数及约束命令
protobuf coding and network communication applications (1)
SQL Server database generation and execution of SQL scripts
Common exception analysis of Redis client
二十一、Kotlin进阶学习:实现简单的网络访问封装
Briefly describe SSRF
【SQL】first_value 应用场景 - 首单 or 复购
Trust anchor for certification path not found.异常解决方法。
Flink CDC implements Postgres to MySQL streaming processing transmission case
二十二、Kotlin进阶学习:简单学习RecyclerView实现列表展示;
mysql删除表中重复数据,(只保留一行)
国内数字藏品交易平台开发市场会开放二级市场吗
Twenty-two, Kotlin advanced learning: simply learn RecyclerView to achieve list display;
Defense Ideas for a Type of SMS Vulnerability