Reputation: 169
After removing the background of the toolbar, with an image mask, a shadow line still remains above the toolbar. How do we get rid of it? As you can see, by the image below, I want to use the toolbar and buttons but no background or top shadow.
const float colorMask[6] = {222, 255, 222, 255, 222, 255};
UIImage *_img = [[UIImage alloc] init];
UIImage *_maskedImage = [UIImage imageWithCGImage:CGImageCreateWithMaskingColors(_img.CGImage, colorMask)];
[self.navigationController.toolbar setBackgroundImage:_maskedImage forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
Upvotes: 6
Views: 5734
Reputation: 221
Add this line also
[toolbar setShadowImage:_maskedImage forToolbarPosition:UIToolbarPositionAny];
Two important notes:
Upvotes: 5
Reputation: 113
None of the other answers worked for me in iOS 7, so here is what I did using Interface Builder:
Doing this will clip the top of the toolbar off and thus remove the gray shadow.
Upvotes: 0
Reputation: 1038
None of the other answers worked on iOS7, some didn't seem to work consistently on older iOS versions either. This (paraphrasing http://samplecodebank.blogspot.com/2013/06/UIToolbar-setShadowImage-forToolbarPosition-example.html) works consistently on 5.1+ for me and is concise and more performant than generating custom background images and color masks.
toolbar.backgroundColor = [UIColor clearColor];
if ([toolbar respondsToSelector:@selector(setBackgroundImage:forToolbarPosition:barMetrics:)]) {
[toolbar setBackgroundImage:[UIImage new] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
}
if ([toolbar respondsToSelector:@selector(setShadowImage:forToolbarPosition:)]) {
[toolbar setShadowImage:[UIImage new] forToolbarPosition:UIToolbarPositionAny];
}
Upvotes: 15
Reputation: 9
setBackgroundImage:_maskedImage need to remove the shadow or else call the customized shadow clear method after toolbar hide
Upvotes: -1
Reputation: 20541
First Add QuartzCore/QuartzCore
framework in your project and after import it this in your .m
file like bellow...
#import <QuartzCore/QuartzCore.h>
and after just add this bellow code...
yourToolBar.layer.shadowOffset = CGSizeMake(0.0f, 0.0f);
yourToolBar.layer.shadowOpacity =0.0f;
yourToolBar.layer.shadowRadius = 0.0f;
hope this helpful to you...
Upvotes: 2