ios - 在代码中测试 UIButtonTypeSystem 是否为 iOS6 定义

标签 ios uibutton

UIButtonTypeSystem 没有在 iOS 6 中定义

如果我输入以下代码会使应用程序崩溃?

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

如何编写代码来检查 UIButtonTypeSystem 是否已定义并防止崩溃?

最佳答案

如果您需要支持 iOS 6,请使用 UIButtonTypeRoundedRect 而不是 UIButtonTypeSystem。然后它将在 iOS 6 和 7 下工作。 在文档中它指出:

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

关于ios - 在代码中测试 UIButtonTypeSystem 是否为 iOS6 定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25784087/

相关文章:

objective-c - 应用程序在 iPhone 5 上崩溃

ios - 使用 ios 使用 swift 进行本地通知

iphone - 下载普通图像与视网膜设备图像 (2x)

ios - Swift - 为多个按钮分配标题

ios - 如何在导航栏中创建后退按钮

ios - Restkit 自定义映射

ios - 当文件在多个选项卡中打开时,Xcode 会丢失语法突出显示

ios - 通过 Interface Builder 更改 UIView 属性

ios - 集中 UIButton 的标题,如 Swift 下面的图片所示

ios - 通过长按代码创建的按钮的弹出窗口