2016-05-30 60 views
0

故事板的自定義UI經常超時,所以我希望爲故事板和設備製作單獨的UI。我的問題是,如何知道drawRectstoryboard被執行Xcode故事板和自定義UI的drawRect控制流程

override func drawRect(rect: CGRect) { 

    let isStoryboard = ... //< How to know this is called for `storyboard` ? 
    if (isStoryboard) { 
     drawForStoryboard() 
    } else { 
     drawForCustomUI() 
    } 

} 

回答

0

我從github找到了一段代碼。看起來好像#if TARGET_INTERFACE_BUILDER可以區分誰執行drawRect

override public func drawRect(rect: CGRect) { 
    #if TARGET_INTERFACE_BUILDER 
     drawIBPlaceholder() 
     #else 
     drawChart() 
    #endif 
}