How to set iOS to UIBarButtonItem image gradient?

Just curious, I configured UIBarButtonItems as follows

+ (UIBarButtonItem *)createBarButtonItemWithTitle:(NSString *)t target:(id)tgt action:(SEL)a
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    UIImage *buttonImage = [[UIImage imageNamed:@"blabla.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 10, 0, 10)];


    CGRect buttonFrame = [button frame];
    buttonFrame.size.width = 35;
    buttonFrame.size.height = buttonImage.size.height;
    [button setFrame:buttonFrame];

    [button setBackgroundImage:buttonImage forState:UIControlStateNormal];

    [button addTarget:tgt action:a forControlEvents:UIControlEventTouchUpInside];

    UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithCustomView:button];

    return buttonItem ;
}

But now I have no shading / gloss effect on the background image of the button ....

Is there a way to do this automatically, or do I need to do this programmatically?

EDIT: Here is a capture, I used a simple green square to make it more obvious.  There's no more shading / glossy effect

+5
source share
1 answer

To fully customize the panel button this way, you need to provide something other than a flat green image in "blabla.png".

Another way to handle this would be to create a limited-style button with your image. Sort of:

UIBarButtonItem* barButton = [UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"blabla.png"] style:UIBarButtonItemStyleBordered target:tgt selector:a];

UIBarButtonItemStyleBordered -y. , .

0

All Articles