[Swift] Storyboard outlet and action
To programmaictlly change the content of app, we need to contect storyboard to a view controller.
To do that, we need to create new file call it 'ProductViewController', subclass should UIViewController:

Delete some uncessary code, the remain code should looks like:
import UIKit
class ProductViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
Link view to controller:
Click the view panel, and on the right side give the Custom class name as 'ProductViewController':

Link ui elements to outlets:
Click 'ctrl' & drag the image point to the code:

Give the name and save.
We can use 'Image Literal' to auto select the image:


DO the same for the label, then the code looks like:
import UIKit
class ProductViewController: UIViewController {
@IBOutlet weak var productNameLabel: UILabel!
@IBOutlet weak var productViewImage: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
productNameLabel.text = "1937 Desk Phone";
productViewImage.image = #imageLiteral(resourceName: "phone-fullscreen3");
}
}
class CourseViewController : UIViewController {
@IBOutlet weak var courseNameLabel: UILabel!
@IBOutlet weak var courseImageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
var courseName = "App Evolution With Swift"
courseNameLabel.text = courseName
courseImageView.image = UIImage(named: "course-badge")
}
}

@IBAction func addProductAction(_ sender: UIButton) {
print("Button tapped")
}
[Swift] Storyboard outlet and action的更多相关文章
- swift - storyboard(故事版)的使用
iOS开发中,苹果公司提供了一种可视化的编程方式:即xib和storyboard,xib相对来说比较灵活,可以在纯代码的项目中使用, 也可以和storyboard配合使用,用法都差不多,下面来总结一下 ...
- IOS Note - Outlet(插座) & Action(动作)
OutletActionViewController.h #import <UIKit/UIKit.h> @interface OutletActionViewController : U ...
- Swift Storyboard找不到类文件
Swift语言引入了Module概念,在通过关键字@objc(类名)做转换的时候,由于Storyboard没有及时更新Module属性,会导致如下两种类型错误: 1 用@objc(类名)标记的Swif ...
- Swift语言Storyboard教程:第一部分
更新记录: 该Storyboard教程由Caroline Begbie更新iOS 8和Swift相关内容.原文作者为教程编纂组的成员Matthijs Hollemans. 2014/12/10更新: ...
- 【转】iOS 9 Storyboard 教程(一上)
转自:http://blog.csdn.net/yangmeng13930719363/article/details/49886547 Storyboard是在iOS5之后新增的一个令人兴奋的功能, ...
- [Swift]UIAlertController 以及 Swift 中的闭包和枚举
原文地址:http://blog.callmewhy.com/2014/10/08/uialertcontroller-swift-closures-enum/ 在 iOS8 的 SDK 中, UIK ...
- Storyboard 全解析
XCode 4.3.2 新功能 - Storyboard 最近开始比较有空在玩 XCode 4.3.2,赫然发现它多了个 Storyboard 的东东. Storyboard 这个东西一般来说是在做创 ...
- 使用Storyboard拖线容易出错的地方
使用Storyboard拖线容易出错的地方: 在Storyboard中,选中某个控件,按住ctrl键进行拖线,建立Outlet和Action后,不能手动再去修改自动生成的代码,然后再次进行连线,这样会 ...
- 浅谈iOS 5的StoryBoard
转自:http://blog.163.com/wangy_0223/blog/static/450146612012318113233218/ 示例代码的Github地址:https://github ...
随机推荐
- 常用的130个vim命令
最近VIM用的也越来越多了...因为确实在慢慢的把win下的编辑习惯转成unix下的编辑习惯..._vimrc也在不断的完善中先贴一下平时在VIM中使用中的命令...有很多也是我没有掌握的 (估计也是 ...
- 如何优雅的写UI——(2)MFC下基于CFormView的文档视图程序
在MFC中可以创建多种类型的窗口程序,如对话框程序.单文档结构程序(非文档/视图结构).单文档(文档/视图结构)以及多文档视图结构程序等. 在编写一般的小工具时,我们的首选显然是对话框程序,不过基于对 ...
- OSI模型与TCP/IP协议族
OSI模型与TCP/IP协议族 年之后,TCP/IP协议族逐渐成为占主导的商用体系结构,广泛应用于Internet中,并通过广泛的測试.而OSI模型从来没有被全然实现过. 一.OSI模型: OSI与I ...
- Intent调用系统拍照程序,返回图片太小的问题
之前採用的方式(返回的照片会被压缩,不能达到预期效果): Intent intent = new Intent(); Intent intent_camera = getPackageManager( ...
- thinkphp缓存使用
thinkphp缓存使用 一.总结 1.这里的缓存不是指的缓存的页面,而是cache,如果你缓存了一个数组,那么你就可以取出这个数组里面的数据进行使用,用法性质和cookie和session有点像 2 ...
- Android手机间使用socket进行文件互传实例
这是一个Android手机间文件传输的例子,两个手机同时装上此app,然后输入接收端的ip,选择文件,可以多选,点确定,就发送到另一个手机,一个简单快捷文件快传实例.可以直接运用到项目中. 下面是文件 ...
- 前端项目中常用es6知识总结 -- let、const及数据类型延伸
项目开发中一些常用的es6知识,主要是为以后分享小程序开发.node+koa项目开发以及vueSSR(vue服务端渲染)做个前置铺垫. 项目开发常用es6介绍 1.块级作用域 let const 2 ...
- 洛谷—— P1080 国王游戏
https://www.luogu.org/problem/show?pid=1080 题目描述 恰逢 H 国国庆,国王邀请 n 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整 ...
- Python数据结构同Json类型数据相互转换的用法
在做Python接口自动化的时候,经常要用到Python数据结构同Json类型数据相互转换来供我们做进一步的验证提供数据,在此做个记录和总结 Python数据结构同Json类型数据相互转换的函数有:j ...
- session 、cookie、token的区别及联系
本文转自:https://blog.csdn.net/jikeehuang/article/details/51488020:https://blog.csdn.net/weixin_37196194 ...