iOS 15.0 Tab Bars笔记

2021-11-23  本文已影响0人  启发禅悟

在iOS 15.0中,Tab Bar的背景也有同Navigation Bars同样的问题,常见的问题就是背景变成透明了,或者内嵌的ScrollView滚动到最底端的时候,Tab Bar的背景变成透明的了。

所以我们同样需要添加scrollEdgeAppearance的值,建议和standardAppearance的值保持一致。例如:

    UITabBarAppearance *tabBarAppearance = [[UITabBarAppearance alloc] init];
    [tabBarAppearance configureWithDefaultBackground];
    [[UITabBar appearance] setStandardAppearance:tabBarAppearance];
    if (@available(iOS 15.0, *)) {
        [[UITabBar appearance] setScrollEdgeAppearance:[UITabBar appearance].standardAppearance];
    }

一般情况下,我们使用系统默认的Tab Bars就可以了,如果需要配置外观,可以通过下面的外观属性进行精确的配置。

例如:

    UITabBarAppearance *tabBarAppearance = [[UITabBarAppearance alloc] init];
    [tabBarAppearance configureWithDefaultBackground];
    UITabBarItemAppearance *stackedLayoutAppearance = [[UITabBarItemAppearance alloc] initWithStyle:UITabBarItemAppearanceStyleStacked];
    stackedLayoutAppearance.normal.iconColor = [UIColor systemPurpleColor];
    stackedLayoutAppearance.selected.iconColor = [UIColor systemBrownColor];
    tabBarAppearance.stackedLayoutAppearance = stackedLayoutAppearance;
    [[UITabBar appearance] setStandardAppearance:tabBarAppearance];
    if (@available(iOS 15.0, *)) {
        [[UITabBar appearance] setScrollEdgeAppearance:[UITabBar appearance].standardAppearance];
    }

如果需要特殊的功能,例如咸鱼风格的Tab Bar,那么一般是自定义Tab Bar来覆盖系统的。

目前我用到的Tab Bar的第三方库,AxcAE_TabBar 还不错,应该能满足各种需求。

上一篇 下一篇

猜你喜欢

热点阅读