3

Is it possible to make just the background semi transparent? If I change the alpha it changes the title and the boarder. I can change the titleLabel.alpha property but it won't go above the buttons Alpha, only below it.

I know I can make a custom one but thought there would be an easier way

Rudiger
  • 6,749
  • 13
  • 51
  • 102
  • so backgroundColor is affecting more than you want? Apologies if this is what you meant by custom but what about using a button with an image where the image is a solid color with the alpha you want? – Adam Eberbach Aug 16 '10 at 23:27
  • backgoundColor changes the color around the outside, not inside. I actually want the boarder of the button too, and if I change the alpha it also changes this. I've tried a blank image or nil and it doesn't have the desired effect – Rudiger Aug 16 '10 at 23:32

1 Answers1

1

Render a blank button with something like this:

UIGraphicsBeginImageContextWithOptions(size,0,0);
[button.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

From there, it's not hard to halve the alpha (fill it with a 50% opaque rect in "DestOver" blend mode before pulling the image out?). Then set it as the background for a custom button.

Icky. Oh well.

Alternatively, you can modify the view in the view hierarchy directly; not recommended, since it tends to break across OS releases.

tc.
  • 33,468
  • 5
  • 78
  • 96