iOS 7 Only App Crashes at Startup

前端 未结 2 1938
生来不讨喜
生来不讨喜 2021-02-18 14:06

I recently changed my xcode project to be iOS 7 only instead of supporting iOS 5. After making this change as soon as the app starts I get this message in the console.



        
相关标签:
2条回答
  • 2021-02-18 14:35

    This problem arises due to giving different NSAttributedString.key and value to attributed String.

    Error: let prefixAttribute = [ NSForegroundColorAttributeName: UIFont(name: "HelveticaNeue-Light", size: 11.0), NSFontAttributeName: UIColor.darkGray]

    Solved: let prefixAttribute = [ NSFontAttributeName: UIFont(name: "HelveticaNeue-Light", size: 11.0), NSForegroundColorAttributeName: UIColor.darkGray]

    I have interchanged colorarrtibute with font and vice versa

    0 讨论(0)
  • 2021-02-18 14:46

    You probably did what I did, and overzealously cut and replaced the compiler warnings for UITextAttributeTextShadowColor and UITextAttributeTextShadowOffset. So you had code that looked like this:

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

    and replaced them both with NSShadowAttributeName, and ended up with some code like this:

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

    What you need to do is have one attribute NSShadowAttributeName, and create an instance of NSShadow that contains the shadow color and shadow offset.

    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];
    
    0 讨论(0)
提交回复
热议问题