2014-09-11 23 views
0

UIButtonTypeSystem沒有在iOS 6中定義在代碼測試中是否爲iOS6定義了UIButtonTypeSystem

如果我把下面的代碼會崩潰應用程序?

if(appSetting.iOSVersion>=7){ 
    photo = [UIButton buttonWithType:UIButtonTypeSystem]; 
}else{ 
    photo = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
} 

如何編碼以檢查UIButtonTypeSystem是否定義並防止崩潰?

回答

1

如果您需要支持iOS 6,則使用UIButtonTypeRoundedRect而不是UIButtonTypeSystem。它然後將兩者的iOS 6和7 在它指出該文檔下工作:

UIButtonTypeSystem一種系統樣式的按鈕,如在導航欄和工具欄所示的那些。適用於iOS 7.0及更高版本。

+0

我嘗試在代碼中使用UIButtonTypeRoundedRect,當它是iOS 7設備時。該圖像未顯示在按鈕中。它顯示藍色按鈕。有些線程推薦使用UIButtonTypeSystem,它的工作原理。在iOS 6中,它會崩潰。 http://stackoverflow.com/questions/18133465/setting-uibutton-image-results-in-blue-button-in-ios-7 – JosephT 2014-09-11 10:19:07

相關問題