When a UIToolBar subclass has its own background, is the bottom half of the toolbar black?

I am subclassing the UIToolBar, this is how I override the drawRect UIToolBar method:

 - (void)drawRect:(CGRect)rect { UIImage *backgroundImage = [UIImage imageNamed:@"UIToolBar_Background.png"]; [backgroundImage drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; } 

The application uses the UINavigationController paradigm initialized using the initWithNavigationBarClass .

Is the bottom half of the toolbar black? UIToolBar_Background.png has a height of 44 pixels (or 88 for the retina). It should not have a bottom half black.

0
ios uinavigationcontroller uitoolbar
Apr 25 '13 at 13:24
source share
1 answer

By subclassing the UIToolBar and overriding the drawRect, you delete some of the UIToolBar's own drawings. Why not use the api look to set the background image:

 [[UIToolbar appearance] setBackgroundImage:[UIImage imageNamed:@"UIToolBar_Background.png"] forToolbarPosition:UIToolbarPositionBottom barMetrics:UIBarMetricsDefault]; 

alternatively, you can use the subclass route, just make sure you call [super drawrect: rect] before you make your own drawing:

 - (void)drawRect:(CGRect)rect { [super drawRect:rect]; UIImage *backgroundImage = [UIImage imageNamed:@"UIToolBar_Background.png"]; [backgroundImage drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; } 
0
Apr 25 '13 at 13:28
source share



All Articles