1. 懒加载
lazy var imageView:UIImageView = {
let imageView = UIImageView()
imageView.image = UIImage.init(named: "big_image")
return imageView
}()
2. 按钮的点击事件
lazy var button:UIButton = {
let button = UIButton()
button.setTitleColor(UIColor.red, for: .normal)
button.backgroundColor = UIColor.white
button.layer.cornerRadius = 2.0
button.layer.masksToBounds = true
button.isHidden = true
button.addTarget(self, action: #selector(buttonClick(_ :)), for: .touchUpInside)
return button
}()
@objc func buttonClick(_ button:UIButton) -> () {
}
3. 协议可选与必选,delegate是否实现协议
protocol ImageViewDelegate: class {
func selectedImage() -> ()
func removeImage(_ index: Int) -> ()
}
@objc protocol ImageCellDelegate: NSObjectProtocol {
@objc optional func imageCelllLikeButtonClick(imageCell: ImageCell, commentId: String, userLiked:Bool) -> ()
@objc optional func imageCellDetalButtonClick(imageCell: ImageCell, content:String) -> ()
}
weak var delegate</