仅限 iOS 7 的应用程序在启动时崩溃



我最近将我的xcode项目更改为仅iOS 7,而不是支持iOS 5。在应用程序启动后立即进行此更改后,我在控制台中收到此消息。

-[UICachedDeviceWhiteColor shadowColor]: unrecognized selector sent to instance 0x156f22f0

我不确定是什么原因造成的。但是使用调试器,我的应用程序委托似乎在第一行代码处崩溃。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window.rootViewController = self.tabBarController; //this line is where it crashes
[self.window makeKeyAndVisible];

任何帮助将不胜感激

你可能做了我所做的,并过度热心地剪切和替换了UITextAttributeTextShadowColor和UITextAttributeTextShadowOffset的编译器警告。所以你有如下所示的代码:

NSDictionary *titleAttributes = @{UITextAttributeTextColor: [UIColor whiteColor],
                                  UITextAttributeTextShadowColor: [UIColor blackColor],
                                  UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(1, 0)],
                                  UITextAttributeFont: [UIFont titleBolder]};
[[UINavigationBar appearance] setTitleTextAttributes:titleAttributes];

并用 NSShadowAttributeName 替换了它们,最后得到了一些这样的代码:

NSDictionary *titleAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor],
                                  NSShadowAttributeName: [UIColor blackColor],
                                  NSShadowAttributeName: [NSValue valueWithUIOffset:UIOffsetMake(1, 0)],
                                  NSFontAttributeName: [UIFont titleBolder]};
[[UINavigationBar appearance] setTitleTextAttributes:titleAttributes];

您需要做的是拥有一个属性 NSShadowAttributeName,并创建一个包含阴影颜色和阴影偏移量的 NSShadow 实例。

NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor blackColor];
shadow.shadowOffset = CGSizeMake(1, 0);
NSDictionary *titleAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor],
                                  NSShadowAttributeName: shadow,
                                  NSFontAttributeName: [UIFont titleBolder]};
[[UINavigationBar appearance] setTitleTextAttributes:titleAttributes];

由于为属性字符串提供不同的 NSAttributedString.key 和值而出现此问题。

错误 :let 前缀属性 = [ NSForegroundColorAttributeName: UIFont(名称: "HelveticaNeue-Light", 大小: 11.0), NSFontAttributeName: UIColor.darkGray]

解决:let 前缀属性 = [ NSFontAttributeName: UIFont(名称: "HelveticaNeue-Light", size: 11.0), NSForegroundColorAttributeName: UIColor.darkGray]

我已经将colorarrtibute与字体互换,反之亦然

最新更新