UINavigationBar 背景透明与渐变

1、UINavigationBar 背景透明(按键还看得到)

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

    [self.navigationController.navigationBar setShadowImage:[UIImage new]];


2、列表上拉,UINavigation背景颜色逐渐变深

思路:上拉的时候不断改变背景颜色的alpha值

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

    CGFloat yoffset = scrollView.contentOffset.y;

    if (yoffset >0) {

        CGFloat alpha = MIN(1, yoffset/150); //150:上拉150距离背景图片alpha=1

        UIImage *image = [self createImageWithColor:[UIColor colorWithRed:73/255.0f green:174/255.0f blue:175/255.0f alpha:alpha]];

        [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];

    }

}


- (UIImage *) createImageWithColor: (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 *myImage =UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return myImage;

}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

机器人开发者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值