0

UIButtonTypeSystem is not defined in iOS 6

if I put the following code will crash the app ?

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

How to code to to check if UIButtonTypeSystem defined and prevent crashing?

JosephT
  • 865
  • 1
  • 11
  • 20

1 Answers1

1

If you need to support iOS 6 then use UIButtonTypeRoundedRect instead of UIButtonTypeSystem. It will then work under both iOS 6 and 7. In the docs it states:

UIButtonTypeSystem A system style button, such as those shown in navigation bars and toolbars. Available in iOS 7.0 and later.

freshking
  • 1,824
  • 18
  • 31
  • I try using UIButtonTypeRoundedRect in the code, when it is iOS 7 device. the image does not shown in the button. It shows blue button instead. Some thread recommend to use UIButtonTypeSystem , it works. In iOS 6 , it crash. http://stackoverflow.com/questions/18133465/setting-uibutton-image-results-in-blue-button-in-ios-7 – JosephT Sep 11 '14 at 10:19