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的更多相关文章

  1. swift - storyboard(故事版)的使用

    iOS开发中,苹果公司提供了一种可视化的编程方式:即xib和storyboard,xib相对来说比较灵活,可以在纯代码的项目中使用, 也可以和storyboard配合使用,用法都差不多,下面来总结一下 ...

  2. IOS Note - Outlet(插座) & Action(动作)

    OutletActionViewController.h #import <UIKit/UIKit.h> @interface OutletActionViewController : U ...

  3. Swift Storyboard找不到类文件

    Swift语言引入了Module概念,在通过关键字@objc(类名)做转换的时候,由于Storyboard没有及时更新Module属性,会导致如下两种类型错误: 1 用@objc(类名)标记的Swif ...

  4. Swift语言Storyboard教程:第一部分

    更新记录: 该Storyboard教程由Caroline Begbie更新iOS 8和Swift相关内容.原文作者为教程编纂组的成员Matthijs Hollemans. 2014/12/10更新:  ...

  5. 【转】iOS 9 Storyboard 教程(一上)

    转自:http://blog.csdn.net/yangmeng13930719363/article/details/49886547 Storyboard是在iOS5之后新增的一个令人兴奋的功能, ...

  6. [Swift]UIAlertController 以及 Swift 中的闭包和枚举

    原文地址:http://blog.callmewhy.com/2014/10/08/uialertcontroller-swift-closures-enum/ 在 iOS8 的 SDK 中, UIK ...

  7. Storyboard 全解析

    XCode 4.3.2 新功能 - Storyboard 最近开始比较有空在玩 XCode 4.3.2,赫然发现它多了个 Storyboard 的东东. Storyboard 这个东西一般来说是在做创 ...

  8. 使用Storyboard拖线容易出错的地方

    使用Storyboard拖线容易出错的地方: 在Storyboard中,选中某个控件,按住ctrl键进行拖线,建立Outlet和Action后,不能手动再去修改自动生成的代码,然后再次进行连线,这样会 ...

  9. 浅谈iOS 5的StoryBoard

    转自:http://blog.163.com/wangy_0223/blog/static/450146612012318113233218/ 示例代码的Github地址:https://github ...

随机推荐

  1. deep-in-es6(二)

    es6-生成器Generators: eg: function* quips(name) { yield "您好"+name+"!"; if(name.star ...

  2. Ueditor 七牛集成

    UEDITOR修改成功的 http://blog.csdn.net/uikoo9/article/details/41844747 http://blog.csdn.net/u010717403/ar ...

  3. Spring有用功能--Profile、WebService、缓存、消息、ORM

    本篇介绍一些Spring与其它框架结合的有用功能,包含:Apache CXF WebService框架.Redis缓存.RabbitMQ消息.MyBatis框架. 另外对于Profile,也是Spri ...

  4. POJ--2516--Minimum Cost【最小费用最大流】

    链接:http://poj.org/problem?id=2516 题意:有k种货物,n个客户对每种货物有一定需求量,有m个仓库.每一个仓库里有一定数量的k种货物.然后k个n*m的矩阵,告诉从各个仓库 ...

  5. 【Android】利用安卓的数据接口、多媒体处理编写内存卡Mp3播放器app

    通过调用安卓的MediaPlayer能够直接完毕Mp3等主流音频的播放,同一时候利用ContentResolver与Cursor能够直接读取安卓内在数据库的信息.直接获取当前sdcard中全部音频的列 ...

  6. 在Qt Creator的项目中添加头文件和库

    在Qt Creator中的工程中,工程通过.pro文件管理. 额外需要连接的连接库unix:LIBS += -L your_lib_path -lyour_libwin32:LIBS += your_ ...

  7. Vue简介以及基本使用

    Vue 是一套构建用户界面的渐进式 框架 框架和库? 框架(基于自身的特点向用户提供一套完整的解决方案,控制权在框架本身,需要使用者按照框架所规定的某种规范进行开发) Vue Angular Reac ...

  8. SpringCloud核心教程 | 第三篇:服务注册与发现 Eureka篇

    Spring Cloud简介 Spring Cloud是一个基于Spring Boot实现的云应用开发工具,它为基于JVM的云应用开发中涉及的配置管理.服务发现.断路器.智能路由.微代理.控制总线.全 ...

  9. Akka边学边写(4)-- MiniRPG

    前面几篇文章用Akka写了HelloWorld和EchoServer,为了更进一步学习Akka,本文将会实现一个非常小的RPG游戏server:MiniRPG. 游戏逻辑 由于是迷你RPG,所以逻辑非 ...

  10. BeautifulSoup的高级应用 之 contents children descendants string strings stripped_strings

    继上一节.BeautifulSoup的高级应用 之 find findAll,这一节,主要解说BeautifulSoup有关的其它几个重要应用函数. 本篇中,所使用的html为: html_doc = ...