iphone - 如何检查某个功能是否适用于特定的 iOS 版本?

标签 iphone objective-c cocoa-touch uinavigationbar appearance

在我的 AppDelegate 中,我使用外观代理制作自定义 UI:

//Setup custom appearances
    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"header"] forBarMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
    [[UIToolbar appearance] setBackgroundImage:[UIImage imageNamed:@"header"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];

这会在 iOS4 中崩溃。如何检查此功能在他们运行的 iOS 版本上是否可用,从而避免崩溃?

最佳答案

不检查操作系统,检查功能是否存在。

if ([[UINavigationBar class] respondsToSelector:@selector(appearance)]) {}

关于iphone - 如何检查某个功能是否适用于特定的 iOS 版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8015192/

相关文章:

iphone - 点击状态栏时 Phonegap Xcode iOS 应用程序崩溃

ios - 在 iOS 中使用模态视图 Controller 的返回值

iphone - 查看iphone设置中是否启用了3G

ios - popToViewController 抛出 NSRangeException

ios - CGContextClearRect 导致背景颜色为黑色

ios - 从层次结构中删除以前的 View Controller

objective-c - 处理中断的音频文件下载

ios - 将事件添加到以编程方式生成的 UIView

iphone - 'NSObject<PageControlDelegate>' 没有可见的@interface 声明选择器 'pageControlPageDidChange:'

ios - 以编程方式创建 UIButton 比使用 Storyboard 模糊