I need to traverse a viewcontroller’s view hierarchy what font is being used. Is there a generic way to determine if the view (and subclass of view) supports fonts? I do not want to do a huge if-then-else:
if ([[view isKindOfClass: [UILabel class]) {
// Do stuff
} else if ([[view isKindOfClass: [UITextField class]) {
// Do stuff
} etc. ...
due to the maintenance issue. I prefer to have a method such as
if ([view canPerform: @selector(getFont:)]) {
// Do stuff
}
but this does not work as one might hope.
You may use the respondsToSelector method, inherited from NSObject.
Or