[Swift] Storyboard outlet and action
2024-08-23 22:41:23
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")
}
最新文章
- android 对sqlite数据库的增删改查等各种操作
- sql 中 in与exists的对比
- andriod studio
- meteor 为基础,联合 Apollo + React + React-Router
- SpringMVC Controller 返回值的可选类型
- 31.从尾到头输出链表[Print linked list from last to first]
- JdbcTemplate 、NamedParameterJdbcTemplate、SimpleJdbcTemplate的区别
- mysql case when 条件过滤
- JS高级——闭包
- JavaScript之ClassName属性学习
- 题目1380:lucky number
- Android MediaCodec硬编兼容性测试方案
- LambdaToSql 发布 兰姆达转换sql
- 敏捷开发相关编辑思想(SOA、DDD、REST、CQRS)
- DocumentBuilderFactory.newInstance() 异常解决
- MVP技术沙龙上海站-SQL BI
- 调皮的程序员:Linux之父雕刻在Linux内核中的故事
- 照葫芦画瓢系列之Java --- Maven的配置
- ansible的管理与剧本
- TensorFlow 神经网络相关函数