0

I'm attempting to build a simple app in Objective C, utilizing an attributes Dictionary in my AppDelegate module to allow me to customize the look of various navigation items of my story layout.

The code builds fine with no errors but as it deploys onto my test device I get a SIGABRT.

I'm using latest version Xcode(9.2); storyboards are all set to "Builds for iOS 8.2 and Later"; Deployment Target is set at 8.1.

I had utilized UITextAttributeTextShadowColor, nil in my code without issues, but that is deprecated since iOS 7.0 so I updated it to NSShadowAttributeName, nil and now it won't work.

What am I doing wrong?

The specific SIGABRT error reads: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIDeviceRGBColor shadowColor]: unrecognized selector sent to instance 0x1d447cf00'.

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    NSDictionary *attribs = [NSDictionary dictionaryWithObjectsAndKeys:
    [UIColor colorWithRed:170.0/255.0 green:21.0/255.0 blue:29.0/255.0 alpha:1.0],
    NSForegroundColorAttributeName,
    [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0],
    NSShadowAttributeName, nil];
    [[UINavigationBar appearance] setTitleTextAttributes: attribs];
    [[UIBarButtonItem appearance] setTitleTextAttributes: attribs forState:UIControlStateNormal];
    return YES;
}
Kiran Sarvaiya
  • 1,318
  • 1
  • 13
  • 37
Art2VR
  • 3
  • 6
  • Larme and CodeChanger both helped me get part of the way there. My issue was even more fundamental; in swapping UI for NS the syntax changes so keys and parameters are the other way round, I must have just got code-blind, so I couldn't see which param was working with which key! I was missing the correct syntax to pair an appropriate NSShadow parameter in my code. – Art2VR Mar 20 '18 at 08:52

2 Answers2

0

You need to do your code updation like this :

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

This will solve your problem of crash.

CodeChanger
  • 7,953
  • 5
  • 49
  • 80
0

Documentation: of NSShadowAttributeName:

The value of this attribute is an NSShadow object. The default value of this property is nil.

Clearly that's not what you do. You gave a UIColor object.

And that's exactly what is saying the error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIDeviceRGBColor shadowColor]: unrecognized selector sent to instance 0x1d447cf00'

It's saying: I tried to call a method shadowColor on a UIDeviceRGBColor (surely a cluster for UIColor) object. But since it doesn't know that method (~ selector, for your level that's the case), I crashed.

Clearly, that's where you can get suspicious. shadowColor that's an available method on NSShadow object. Maybe I did something wrong. And reading the doc you'll know it's the case.

So put a NSShadow object instead of a UIColor one for the value corresponding.

Larme
  • 24,190
  • 6
  • 51
  • 81