iOS 13导航栏和状态栏设置背景渐变色

在iOS13以上设置系统导航栏背景色

if (@available(iOS 13.0, *)) {
            // Create a navigation bar appearance
            UINavigationBarAppearance *navigationBarAppearance = [[UINavigationBarAppearance alloc] init];
            [navigationBarAppearance configureWithDefaultBackground];

            // Create a gradient layer
            CAGradientLayer *gradientLayer = [CAGradientLayer layer];
            gradientLayer.colors = @[(id)[UIColor blueColor].CGColor, (id)[UIColor greenColor].CGColor]; // Customize the gradient colors
            gradientLayer.startPoint = CGPointMake(0.0, 0.0); // Gradient start point
            gradientLayer.endPoint = CGPointMake(1.0, 0.0);   // Gradient end point

            // Apply gradient layer to the navigation bar background
            navigationBarAppearance.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]; // Add blur effect

            // Create an image renderer
            UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:CGSizeMake(1, 1)];
            UIImage *backgroundImage = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull context) {
                gradientLayer.frame = CGRectMake(0, 0, context.format.bounds.size.width, context.format.bounds.size.height);
                [gradientLayer renderInContext:context.CGContext];
            }];

            navigationBarAppearance.backgroundImage = backgroundImage;

            // Set the navigation bar appearance
            controller.navigationController.navigationBar.standardAppearance = navigationBarAppearance;
            controller.navigationController.navigationBar.scrollEdgeAppearance = navigationBarAppearance;
        }

效果:


11.png
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容