Search code examples
iosios7uitoolbar

UIToolBar lose translucent when clipsToBounds in iOS7.x


Usually i use UIToolBar to fake the live blur effect, it has been working great for me. But there is a place I need to have a rounded corner toolbar, however, whenever I set the cornerRadius and clipsToBounds, the translucent (blur) effect is gone, my tool bar becomes transparent.

here is my code:

UIToolbar *blurView = [[UIToolbar alloc] initWithFrame:self.bounds];
blurView.barStyle = UIBarStyleBlack;
blurView.layer.cornerRadius = self.height / 2;
blurView.clipsToBounds = YES;
[self insertSubview:blurView atIndex:0];

here is a screen shot when clipsToBounds = YES, the corner is rounded, but the blur is gone.

enter image description here

But if i comment clipsToBounds out, the blur effect is back, but the corner is not rounded anymore.

enter image description here

The even stranger part is this issue only happens in iOS7.x, everything works perfectly in iOS8.x with the exactly same codes.

just in case if you wondering, here is how it looks on iOS8.x and how it should look on iOS7.x

enter image description here

I have been searching around on Stackoverflow and Google, can't find any clue. Please Help!


Solution

  • Try blurView.layer.cornerRadius = self.height / 2 - 0.5;