NavigationBar
//基本不用
// NSShadow *shadow = [[NSShadow alloc] init];
// shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0]; // 阴影颜色
// shadow.shadowOffset = CGSizeMake(0, 2); // 阴影偏移量
//设置背景颜色、文字属性
NSDictionary *titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor],
NSFontAttributeName : [UIFont systemFontOfSize:18 weight:UIFontWeightMedium],};
// NSShadowAttributeName:shadow};
if (@available(iOS 13.0, *)) {
UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
appearance.backgroundEffect = nil;
appearance.backgroundColor = [UIColor redColor];
appearance.backgroundImage = image;
appearance.titleTextAttributes = titleTextAttributes;
// 将设置应用到导航栏的 standardAppearance 和 scrollEdgeAppearance
self.navigationController.navigationBar.standardAppearance = appearance;
self.navigationController.navigationBar.scrollEdgeAppearance = appearance;
} else {
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
[self.navigationController.navigationBar setTitleTextAttributes:titleTextAttributes];
//阴影线
self.navigationController.navigationBar.shadowImage = [UIImage new];
// 透明
self.navigationController.navigationBar.translucent = NO;
// 背景图片
[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
//背景颜色
self.navigationController.navigationBar.backgroundColor = [UIColor redColor];
}
// 创建返回按钮
UIBarButtonItem *backBtn = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backBtn;
TabBar
if (@available(iOS 13.0, *)) {
UITabBarAppearance *tabbarAppearnce = [[UITabBarAppearance alloc]init];
UITabBarItemAppearance *itemAppearance = [[UITabBarItemAppearance alloc] initWithStyle:(UITabBarItemAppearanceStyleStacked)];
itemAppearance.normal.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor purpleColor]};
itemAppearance.selected.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor redColor]};
// itemAppearance.normal.iconColor = [UIColor blueColor];
// itemAppearance.selected.iconColor = [UIColor redColor];
// itemAppearance.normal.badgeBackgroundColor = [UIColor yellowColor];
// itemAppearance.selected.badgeBackgroundColor = [UIColor yellowColor];
// itemAppearance.normal.badgeTextAttributes = @{NSForegroundColorAttributeName:[UIColor redColor]};
tabbarAppearnce.stackedLayoutAppearance = itemAppearance;
tabbarAppearnce.backgroundColor = [UIColor orangeColor];
tabbarAppearnce.backgroundEffect = nil;
self.tabBar.standardAppearance = tabbarAppearnce;
if (@available(iOS 15.0, *)) {
self.tabBar.scrollEdgeAppearance = tabbarAppearnce;
}
}else{
//背景颜色
self.tabBar.backgroundColor = [UIColor orangeColor];
//选中颜色
self.tabBar.tintColor = [UIColor redColor];
//没有选中的颜色
self.tabBar.unselectedItemTintColor = [UIColor whiteColor];
//去掉黑线
self.tabBar.shadowImage = [UIImage new];
}
网友评论