Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does [[UINavigationBar appearance] setTranslucent:NO] crash my app?

Same question as this, but that question was shunned (because of NDA at the time) and is no longer active.

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** Illegal property type, c for appearance setter, _installAppearanceSwizzlesForSetter:'

I'm setting this in viewDidLoad of my initial view controller. setTranslucent comes up on autocomplete, and does not complain until crashing and talking about swizzles and things.

Any info on this would be great, I'm still having a very rough time getting a consistent status bar appearance across my app.

like image 418
user Avatar asked Oct 01 '13 20:10

user


People also ask

What is isTranslucent?

isTranslucent: A Boolean value indicating whether the navigation bar is translucent (true) or not (false). isOpaque: A Boolean value indicating whether the title is empty and an opaque bezel is set.

What is Scrolledgeappearance?

The appearance settings for the navigation bar when the edge of scrollable content aligns with the edge of the navigation bar. iOS 13.0+ iPadOS 13.0+ Mac Catalyst 13.1+ tvOS 13.0+

How do you make a navigation bar transparent in Swift?

You need to do three things to make a navigation bar transparent. Set background image to non-nil empty image ( UIImage() ). Set shadow image to non-nil empty image ( UIImage() ).


2 Answers

It seems that the translucent property just can't be set using UIAppearance. I don't know exactly why, but I guess some properties just aren't supported. However, I solved this by creating a custom UIViewController and making all other viewControllers in my app a subclass of that custom viewController. That way, I can set global properties (such as translucent in your case) that will be inherited by all other viewControllers in my app. I know that's kind of a big change, but I hope it helps.

**** EDIT ****

As of iOS 8, translucency can be set with UIAppearance:

Objective C

if([UIDevice currentDevice].systemVersion.floatValue >= 8.0) {

    [[UINavigationBar appearance] setTranslucent:YES];
}

Swift

if (UIDevice.currentDevice().systemVersion as NSString).floatValue >= 8.0 {

    UINavigationBar.appearance().translucent = true
}
like image 79
hgwhittle Avatar answered Nov 01 '22 05:11

hgwhittle


You can fool it though by specifying a non exist image, which will amke the tool bar go opaque

[[UIToolbar appearance] setBackgroundColor:[UIColor colorWithRed:219.0/255.0 green:67.0/255.0 blue:67.0/255.0 alpha:1.0]];

[[UIToolbar appearance] setBackgroundImage:[[UIImage alloc] init] forToolbarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
like image 8
JulianB Avatar answered Nov 01 '22 04:11

JulianB