我收到错误的self.view说' UIViewController.Type'没有名为' view'的成员
extension UIViewController {
class func addBackgroundImage() {
let backgroundImageView = UIImageView();
let backgroundImage = UIImage(named: "splashBackground");
backgroundImageView.image = backgroundImage;
self.view.addSubview(backgroundImageView);
let insets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
backgroundImageView.autoPinEdgesToSuperviewEdgesWithInsets(insets)
}
答案 0 :(得分:2)
您已将addBackgroundImage
定义为class func
。这意味着self
将是类对象,而不是类的实例。
改为使用func addBackgroundImage() { ... }
。