Home > Software design >  No visible @interface for UITabBar setScrollEdgeAppearance
No visible @interface for UITabBar setScrollEdgeAppearance

Time:09-16

today i met with issue on Xcode 12. When i tried iOS 15 version of app i noticed that tabbar background changed. I solved this by adding this line of code

if (@available(iOS 15.0, *)) {
    [[UITabBar appearance] setScrollEdgeAppearance:tabBarAppearance.appearance];
}

But after I swapped back to Xcode 12 from Xcode 13 i got this issue.

No visible @interface for 'UITabBar' declares the selector 'setScrollEdgeAppearance:'

Seems like Xcode12 bug for me but maybe i am wrong.

Edit: added if statement which was in code

CodePudding user response:

I think that's because scrollEdgeAppearance was just a property of UINavigationBar for iOS < 15 versions. Since iOS 15 They've extended it to all others navigation bars

As per Apple doc:

When running on apps that use iOS 14 or earlier, this property applies to navigation bars with large titles. In iOS 15, this property applies to all navigation bars.

CodePudding user response:

This property is available only starting with iOS 13. Here is a declaration from corresponding API header:

/// Describes the appearance attributes for the navigation bar to use when an associated UIScrollView has reached the edge abutting the bar (the top edge for the navigation bar). If not set, a modified standardAppearance will be used instead.
@property (nonatomic, readwrite, copy, nullable) UINavigationBarAppearance *scrollEdgeAppearance UI_APPEARANCE_SELECTOR API_AVAILABLE(ios(13.0));

You can use it with conditional compilation, like

if (@available(iOS 13.0, *))
{
   [[UITabBar appearance] setScrollEdgeAppearance:tabBarAppearance.appearance];
}

but you should build the project with latest SDK keeping deployment target to your minimal supported system (presumably iOS 12)

Update: dynamic variant of selector usage

if (@available(iOS 13.0, *))
{
   [[UITabBar appearance] 
       performSelector:@selector(setScrollEdgeAppearance:) 
       withObject:tabBarAppearance.appearance];
}
  • Related