[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 ...
随机推荐
- BZOJ——T 1355: [Baltic2009]Radio Transmission
http://www.lydsy.com/JudgeOnline/problem.php?id=1355 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: ...
- 平衡树之RB-tree
#include <memory> template<class T> struct rb_node { T key; bool color;//true red | fals ...
- Nio学习3——基础模型:多路复用模型
Reactor模式和NIO 本文可看成是对Doug Lea Scalable IO in Java一文的翻译. 当前分布式计算 Web Services盛行天下,这些网络服务的底层都离不开对socke ...
- 华为畅玩5 (CUN-AL00) 刷入第三方twrp Recovery 及 root
华为畅玩5 (CUN-AL00) 刷入第三方twrp Recovery 及 root 下载地址 http://pan.baidu.com/s/1hsn6VzA 1. 在官网申请解锁码 申 ...
- APACHE2.4 指定目录中的字符编码
APACHE2.4 指定目录中的字符编码 xampp 的 apache2.4 默认字符编码是西文,中文字符显示乱码,在 httpd.conf 没有 AddDefaultCharset utf-8 这样 ...
- eclipse - 下载网址
这里面有着非常齐全的eclipse相关资源,而且都是放在网盘里面的,下载也方便 http://www.androiddevtools.cn/
- ConcurrentHashMap实现原理--转载
原文地址:http://ajax-xu.iteye.com/blog/1104649 ConcurrentHashMap是Java 5中支持高并发.高吞吐量的线程安全HashMap实现.在这之前我对C ...
- InstallShield详细制作说明(二)
四.设置安装的组件Component
- 使用PyCharm安装第三方库
使用PyCharm安装第三方库是一种十分简单的做法,接下来我来演示一下在PyCharm上安装第三方库requess的操作流程. 首先,先看一下当第三方库未安装时的提示内容,在pycharm中新建pyt ...
- textview-调节字体间距跟行距
直接进行代码验证 1)当没有添加字体间距属性的时候 <TextView android:id="@+id/text_view" android:layout_width=&q ...