ios - When subclassing UIToolBar to have a custom background the bottom half of toolbar is black? -


i'm subclassing uitoolbar, here how override drawrect method of uitoolbar:

- (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 app uses uinavigationcontroller paradigm initialized initwithnavigationbarclass method.

the issue bottom half of toolbar black? uitoolbar_background.png 44 pixels height (or 88 retina). should not have it's bottom half black.

by subclassing uitoolbar , overriding drawrect, eliminate of uitoolbar's own drawing. why not use appearance api set background image:

[[uitoolbar appearance] setbackgroundimage:[uiimage imagenamed:@"uitoolbar_background.png"]                         fortoolbarposition:uitoolbarpositionbottom                                 barmetrics:uibarmetricsdefault]; 

alternatively, use subclassing route, make sure call [super drawrect:rect] before doing 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)]; } 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -