views:

115

answers:

1

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

A: 

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.
In a nutshell this is bad either way. I ended up making a custom one
Rudiger