Sreejith
Sreejith

Reputation: 1355

iOS can't set background color for FXBlurView

I'm using FXBlur to achieve blur-effect for an underlying view. But the background color which I set is never seen while running.

I have a "Main View" inside which there is an Image and a Blur View. Blur View has a grey background.

The Image is getting blurred but I can't see the grey color which I had set for the Blur View. No matter what I try, I can't set the backgrund color and achieve the blur effect simultaneously.

What might be the issue? Is there any workaround?

EDITED :

self.blurView.dynamic = NO;
self.blurView.tintColor = [UIColor grayColor];
self.blurView.contentMode = UIViewContentModeBottom;

Upvotes: 5

Views: 2289

Answers (2)

Nick Lockwood
Nick Lockwood

Reputation: 40995

The blurView tintColor uses additive blending, so making it grey won't have much effect.

If you want to add a grey overlay to darken your blur view, add a subview with a partially transparent grey backgroundColor inside the blurView.

Upvotes: 11

Sreejith
Sreejith

Reputation: 1355

Finally, I was able to achieve the same using a Toolbar and a CALayer. Here is the code :

UIToolbar *toolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, self.blurView.frame.size.width, self.blurView.frame.size.height)];
[self.blurView addSubview:toolbar.superview];

CALayer *extraColorLayer = [CALayer layer];
extraColorLayer.frame = CGRectMake(0, 0, toolbar.frame.size.width, toolbar.frame.size.height);
extraColorLayer.backgroundColor = [UIColor colorWithRed:126/255 green:126/255 blue:126/255 alpha:0.4].CGColor;
[self.blurView.superview.layer addSublayer:extraColorLayer];

Thanks all.

Upvotes: 0

Related Questions