开发者

UIButton only background slightly transparent

开发者 https://www.devze.com 2023-01-12 08:05 出处:网络
Is it possible to make just the background开发者_JAVA技巧 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 abov

Is it possible to make just the background开发者_JAVA技巧 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消