2016-05-13 33 views
1
public protocol NavigationBarNormalStyle { 
    var titleView: UIToolbar! {get} 
    var rightButton: UIButton? {get} 
} 

public extension NavigationBarNormalStyle where Self == UIViewController { 

    var titleView:UIToolbar { 
     var titleViewBar = UIToolbar(frame: CGRect(x: 0.0, y: 0.0, width:Self.view.width, height: 44)) 
     titleViewBar.barTintColor = UIColor.whiteColor() 
     Self.view.addSubview(titleViewBar) 
    } 

} 

Self.view.width是錯誤的...如何使用VC的財產?擴展協議如何使用的有關的UIViewController的UIViewController的財產

回答

0

要訪問實例屬性,但Self是對象的,而不是對象本身。

你應該寫self.view