美文网首页
iOS 导航栏渐变

iOS 导航栏渐变

作者: a7cdfadad9f2 | 来源:发表于2017-06-21 08:46 被阅读0次

    -(void)scrollViewDidScroll:(UIScrollView *)scrollView{

    if (scrollView==self.ActivityTableview) {

    //        NSLog(@"%f",scrollView.contentOffset.y);

    CGFloat offsetY = scrollView.contentOffset.y;

    if (scrollView.contentOffset.y>=-20 && scrollView.contentOffset.y<50) {

    [self.navigationController.navigationBar setBackgroundColor:[UIColor colorWithRed:255/255.0f green:255/255.0f  blue:255/255.0f  alpha:offsetY*2/100]];

    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil]];

    [self setStatusBarBackgroundColor:[UIColor colorWithRed:255/255.0f green:255/255.0f  blue:255/255.0f  alpha:offsetY*2/100]];

    //NSLog(@"变色");

    }else if (scrollView.contentOffset.y<-20){

    [self.navigationController.navigationBar setBackgroundColor:[UIColor colorWithRed:226/255.0f green:67/255.0f  blue:70/255.0f  alpha:0.0]];

    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil]];

    [self setStatusBarBackgroundColor:[UIColor colorWithRed:226/255.0f green:67/255.0f  blue:70/255.0f  alpha:0.0]];

    }else{

    [self.navigationController.navigationBar setBackgroundColor:[UIColor whiteColor]];

    //            [self.navigationController.navigationBar setTintColor:[UIColor blackColor]];

    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor], NSForegroundColorAttributeName, nil]];

    [self setStatusBarBackgroundColor:[UIColor whiteColor]];

    }

    }

    }

    - (void)setStatusBarBackgroundColor:(UIColor *)color {

    UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];

    if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {

    statusBar.backgroundColor = color;

    }

    }

    相关文章

      网友评论

          本文标题:iOS 导航栏渐变

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