Apparently you cannot.
The methods suggested by other answers will break easily, here's an example:
UINavigationBar
instances respond to selectorsetTranslucent:
- However
setTranslucent:
is not tagged withUI_APPEARANCE_SELECTOR
in the header file
Therefore the following code
if([[UINavigationBar class] instancesRespondToSelector:@selector(setTranslucent:)]) {
[[UINavigationBar appearance] setTranslucent:NO]; // BUM!
}
will result in a crash.
The only information about which selectors conform to UIAppearance
seems to be the UI_APPEARANCE_SELECTOR
macro, which is stripped at compile-time.
A runtime check doesn't look to be feasible.
For the sake of completeness, here's an awful (but practical) way of doing it.
@try {
[[UINavigationBar appearance] setTranslucent:YES];
} @catch (NSException *exception) {
if ([exception.name isEqualToString:@"NSInvalidArgumentException"])
NSLog(@"Woops");
else
@throw;
}
However, this is very fragile since there's no guarantee that you're catching only the case in which the selector doesn't conform to UIAppearance
.