iOS 在didSet中初始化属性
示例
@IBOutlet weak var title: UILabel! { didSet { label.textColor= UIColor.redColor() label.font= UIFont.systemFontOfSize(20) label.backgroundColor= UIColor.blueColor() } }
也可以设置一个值并对其进行初始化:
private var loginButton = UIButton() { didSet(oldValue) { loginButton.addTarget(self, action: #selector(LoginController.didClickLogin), forControlEvents: .TouchUpInside) } }