美文网首页
iOS 15 导航栏 底部TableBar 适配

iOS 15 导航栏 底部TableBar 适配

作者: 家振要翻天 | 来源:发表于2021-10-30 11:40 被阅读0次

从 iOS 15 开始,UINavigationBar、UIToolbar 和 UITabBar 在控制器中关联滚动视图顶部或底部时使用UINavigationBar.scrollEdgeAppearance配置相关属性-背景、字体等

Tablear 代码

 if (@available(iOS 15.0, *)) {
        UITabBarAppearance * appearance = [[UITabBarAppearance alloc] init];
        [appearance configureWithOpaqueBackground];
        appearance.backgroundColor = UIColor.whiteColor;
        [UITabBar appearance].scrollEdgeAppearance = appearance;
        [UITabBar appearance].standardAppearance = appearance;
    }
    [UITabBar appearance].backgroundColor = UIColor.whiteColor;

NavigationBar 代码

    if ( @available(iOS 15.0, *) ) {
        
        UINavigationBarAppearance * appearance1 = [[UINavigationBarAppearance alloc] init];
        [appearance1 configureWithOpaqueBackground];
        appearance1.backgroundColor = KnavigationbarColor;
        
        NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
            [attributes setValue:UIColor.whiteColor forKey:NSForegroundColorAttributeName];
        appearance1.titleTextAttributes = attributes;
        [UINavigationBar appearance].standardAppearance = appearance1;
            [UINavigationBar appearance].scrollEdgeAppearance = appearance1;        
        [[UINavigationBar appearance] setScrollEdgeAppearance:appearance1];
        [[UINavigationBar appearance]setStandardAppearance:appearance1];
        
    }

iOS15中tableviewController 中新增
TableView 增加sectionHeaderTopPadding属性,默认情况sectionHeaderTopPadding会有22个像素的高度,及默认情况,TableView section header增加22像素的高度

if #available(iOS 15.0, *) {
      self.tableView.sectionHeaderTopPadding = 0
}

相关文章

网友评论

      本文标题:iOS 15 导航栏 底部TableBar 适配

      本文链接:https://www.haomeiwen.com/subject/wbjgaltx.html