“我正在参与「启航计划」”

导言

布景: 去掉导航栏下边的黑边在iOS15失效 原因:必须使用iOS13之后的APIUINavigationBarAppearance设置才干生效

UIKIT_EXTERN API_AVAILABLE(ios(13.0), tvos(13.0)) NS_SWIFT_UI_ACTOR
@interface UINavigationBarAppearance : UIBarAppearance

I 导航栏的黑边设置

1.1 去掉导航栏下边的黑边(iOS15适配)

iOS小技能:去掉/新增导航栏黑边(iOS13适配)

iOS15之前: [self.navigationBar setShadowImage:[[UIImage alloc] init]];

        [vc.navigationController.navigationBar setBackgroundImage:[ImageTools createImageWithColor: [UIColor whiteColor]] forBarMetrics:UIBarMetricsDefault];

iOS15之后


    if(@available(iOS 13.0, *)) {
        UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
        //去掉透明后导航栏下边的黑边
        appearance.shadowImage =[[UIImage alloc] init];
        appearance.shadowColor= UIColor.clearColor;
        navigationBar.standardAppearance = appearance;
        navigationBar.scrollEdgeAppearance = appearance;
    }

1.2 设置导航栏下边的黑边(iOS13适配)

iOS小技能:去掉/新增导航栏黑边(iOS13适配)


// 设置导航栏下边的黑边
+ (void)setupnavigationBar:(UIViewController*)vc{
    if (@available(iOS 13.0, *)) {
        UINavigationBar *navigationBar = vc.navigationController.navigationBar;
        UINavigationBarAppearance *appearance =navigationBar.standardAppearance;
        appearance.shadowImage =[UIImage createImageWithColor:k_tableView_Line];
        appearance.shadowColor=k_tableView_Line;
        navigationBar.standardAppearance = appearance;
        navigationBar.scrollEdgeAppearance = appearance;
    } else {
        // Fallback on earlier versions
        UINavigationBar *navigationBar = vc.navigationController.navigationBar;
        [navigationBar setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault]; //此处使底部线条色彩为红色
//        [navigationBar setShadowImage:[UIImage createImageWithColor:[UIColor redColor]]];
        [navigationBar setShadowImage:[UIImage createImageWithColor:k_tableView_Line]];
    }
}

II 去掉TabBar的顶部黑线

iOS小技能:去掉/新增导航栏黑边(iOS13适配)

  • setupshadowColor

- (void)setupshadowColor{
    UIView * tmpView = self;
    tmpView.layer.shadowColor = [UIColor blackColor].CGColor;//设置暗影的色彩
    tmpView.layer.shadowOpacity = 0.08;//设置暗影的透明度
    tmpView.layer.shadowOffset = CGSizeMake(kAdjustRatio(0), kAdjustRatio(-5));//设置暗影的偏移量,暗影的大小,x往右和y往下是正
    tmpView.layer.shadowRadius = kAdjustRatio(5);//设置暗影的圆角,//暗影的扩散规模,相当于blur radius,也是shadow的突变距离,从外围开端,往里突变shadowRadius距离
//去掉TabBar的顶部黑线    
[self setBackgroundImage:[UIImage createImageWithColor:[UIColor clearColor]]];
[self setShadowImage:[UIImage createImageWithColor:[UIColor clearColor]]];
}

see also

iOS小技能:自定义导航栏,设置大局导航条外观。(iOS15适配) blog.csdn.net/z929118967/…