美文网首页
[iOS功能]- UINavigationController-

[iOS功能]- UINavigationController-

作者: AlwaysLuckyMa | 来源:发表于2019-11-26 11:57 被阅读0次

    隐藏导航栏底部的线条
    方法1 (单页面设置)

    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
    

    如果不想影响其他页面的导航透明度,viewWillDisappear将其设置为nil即可:

    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:nil];
    

    方法2(全局设置)

    [[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
     
    [[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
    

    方法3

    self.navigationController.navigationBar.clipsToBounds = YES;
    

    设置导航栏底部线条颜色的代码:

    UINavigationBar *navigationBar = self.navigationController.navigationBar; 
    [navigationBar setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault]; //此处使底部线条颜色为红色
    [navigationBar setShadowImage:[UIImage imageWithColor:[UIColor redColor]]];
    
    @implementation UIImage (ColorImage)
    + (UIImage *)imageWithColor:(UIColor *)color{ 
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); 
    UIGraphicsBeginImageContext(rect.size); 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextSetFillColorWithColor(context, [color CGColor]); 
    CGContextFillRect(context, rect); 
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); return image;
    }@end
    

    修复navigationController侧滑关闭失效的问题

    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self
    

    隐藏返回按钮后面的文字

     [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)
                                                             forBarMetrics:UIBarMetricsDefault];
    

    转自:
    https://blog.csdn.net/wujakf/article/details/78584325

    相关文章

      网友评论

          本文标题:[iOS功能]- UINavigationController-

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