Trying out iOS 7 did:
[[UINavigationBar appearance] setTranslucent:NO];
Got crash and error:
*** Terminating app due to
I solved it with my own category so that I can still use UIAppearance in something like the normal manner.
@interface UINavigationBar (MMTranlucenceUIAppearance)
@property(nonatomic,assign,getter=isMMTranslucent) NSInteger LYTranslucent NS_AVAILABLE_IOS(3_0) UI_APPEARANCE_SELECTOR; // Default is NO on iOS 6 and earlier. Always YES if barStyle is set to UIBarStyleBlackTranslucent
@end
@implementation UINavigationBar (MMTranlucenceUIAppearance)
// it appears that UIAppearance fails with BOOL
-(NSInteger)isMMTranslucent
{
return self.translucent ? 0 : 1;
}
-(void)setMMTranslucent:(NSInteger)translucent
{
self.translucent = (translucent == 0) ? NO : YES;
}
@end
[[UINavigationBar appearance] setTranslucent:NO]
It is not available iOS 6.It is only available in iOS 7 onward.
Here's code to work around it. The problem is that UIAppearance won't work on BOOL types. This should not be grounds for app rejection, as it uses standard (albeit hacky) procedures. Have fun.
@protocol _UITranslucentThingHack
@property (nonatomic) BOOL translucent;
@end
@interface UIView (_UITranslucentAppearanceProxyHack)
@property (nonatomic) NSNumber * translucentPropertyAsObject;
@end
@implementation UIView (_UITranslucentAppearanceProxyHack)
-(void)setTranslucentPropertyAsObject:(NSNumber *)translucentPropertyAsObject {
if([self respondsToSelector:@selector(setTranslucent:)]) {
id<_UITranslucentThingHack> trans = (id)self;
trans.translucent = [translucentPropertyAsObject boolValue];
}
}
-(NSNumber*)translucentPropertyAsObject {
if([self respondsToSelector:@selector(setTranslucent:)]) {
id<_UITranslucentThingHack> trans = (id)self;
return @(trans.translucent);
}
return nil;
}
@end
Dont know what about the iOS 7 .But in iOS6, according to the documentation you cannot set the translucent property to the UIAppearance object of the UINavigationBar. Some time it shows the all the possibilities in the autocomplete with unsupported one also