iPhone iOS how to add linear gradient to a UIButton under the button's text or image?

Add it to the layer of your custom button:

CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = customButton.layer.bounds;

gradientLayer.colors = [NSArray arrayWithObjects:
                        (id)[UIColor colorWithWhite:1.0f alpha:0.1f].CGColor,
                        (id)[UIColor colorWithWhite:0.4f alpha:0.5f].CGColor,
                        nil];

gradientLayer.locations = [NSArray arrayWithObjects:
                           [NSNumber numberWithFloat:0.0f],
                           [NSNumber numberWithFloat:1.0f],
                           nil];

gradientLayer.cornerRadius = customButton.layer.cornerRadius;
[customButton.layer addSublayer:gradientLayer];

where customButton is your custom UIButton.


For what you are trying to achieve, always insert at index 0.

I wrote an article about this sort of thing recently that you may find interesting.