美文网首页
模仿微信的 navigation

模仿微信的 navigation

作者: __Objc | 来源:发表于2017-08-28 17:26 被阅读11次

    一直觉得微信的导航栏穿透效果很好看
    所以找了点方法模仿一下
    直接上代码

    NSShadow *shadow = [[NSShadow alloc] init];
        shadow.shadowColor = [UIColor colorWithWhite:0.0f alpha:1.0f];
        shadow.shadowOffset = CGSizeMake(0, 0);
        [[UIApplication sharedApplication]registerNotifications];
        [[UINavigationBar appearance] setTitleTextAttributes:@{
                                                               NSForegroundColorAttributeName: [UIColor whiteColor],
                                                               NSShadowAttributeName: shadow,
                                                               NSFontAttributeName: [UIFont fontWithName:@"Arial-BoldMT" size:17.0f]
                                                               }];
        
        [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
        [[UINavigationBar appearance] setBarTintColor:[UIColor appNavigationBarColor]];
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
        
           [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarOrientationChange:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
    
    直接加一个shadow
    
    
    

    方法二

    let blurBackView = UIView()
    blurBackView.frame = CGRect(x: 0, y: -20, width: kScreenW, height: 64)
    let gradintLayer = CAGradientLayer()
    gradintLayer.frame = CGRect(x: 0, y: 0, width: kScreenW, height: 64)
    gradintLayer.colors = [
        UIColor.hexInt(0x040012).withAlphaComponent(0.76).cgColor,
        UIColor.hexInt(0x040012).withAlphaComponent(0.28).cgColor
    ]
    gradintLayer.startPoint = CGPoint(x: 0, y: 0)
    gradintLayer.endPoint = CGPoint(x: 0, y: 1.0)
    blurBackView.layer.addSublayer(gradintLayer)
    blurBackView.isUserInteractionEnabled = false
    blurBackView.alpha = 0.5
    
    // 设置导航栏样式
    navigationBar.barStyle = .black
    navigationBar.insertSubview(blurBackView, at: 0)
    
    
    

    第三种

    UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, bgImgView.frame.size.width*0.5, bgImgView.frame.size.height)];
    toolbar.barStyle = UIBarStyleBlackTranslucent;
    [bgImgView addSubview:toolbar];
    
    

    第四种

    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
    effectView.frame = CGRectMake(0, 0, bgImgView.frame.size.width*0.5, bgImgView.frame.size.height);
    
    

    相关文章

      网友评论

          本文标题:模仿微信的 navigation

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