Slide 18
Slide 18 text
protocol CodeViewFactoryOwner: class {
var titleLabel: UILabel! { get set }
var captionLabel: UILabel! { get set }
var imageView: UIImageView! { get set }
}
class CodeViewFactory: CodeViewFactoryType {
func create(owner:CodeViewFactoryOwner) -> UIView {
return MyCodeView(owner: owner, frame: .zero)
}
}
class MyCodeView: UIView {
init(owner:CodeViewFactoryOwner, frame: CGRect) {
super.init(frame: frame)
self.backgroundColor = .white
let imageView = UIImageView()
let titleLabel = UILabel()
let captionLabel = UILabel()
let button = UIButton(type: .system)
button.setTitle("Play", for: .normal)
button.addTarget(owner, action: Selector(("clickPlay:")), for: .touchUpInside)
self.addSubview(imageView)
self.addSubview(titleLabel)
self.addSubview(captionLabel)
self.addSubview(button)
owner.imageView = imageView
owner.captionLabel = captionLabel
owner.titleLabel = titleLabel
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}