Search code examples
iphoneiosobjective-cuitoolbar

UIToolbar gradient fix


I am using UIToolbar in my project for this lock screen. Everything is fine except the gradient on the UIToolbar is very short. I mean its height is not equal. I have attached the screen shot. I want the UIToolbar to be like figure B.

Any idea how to achieve this.enter image description here


Solution

  • Best thing you can do is setting appearance for your UIToolBar:

    UIImage *gradientImage = [[UIImage imageNamed:@"upperBar.png"]
                                    resizableImageWithCapInsets:UIEdgeInsetsMake(-4, 300, 10, 300)];
    UIToolbar *toolbar = [UIToolBar appearance];
    [toolbar setBackgroundImage:gradientImage forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
    

    Where upperBar.png is the gradient image you want.