UIButton only background slightly transparent

Is it possible to make only semi transparent? If I change the alpha, it will change the name and borders. I can change the titleLabel.alpha property, but it will not exceed the Alpha button, only lower.

I know that I can do the usual, but I thought it would be easier.

+3
source share
1 answer

Make an empty button with something like this:

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

From there, it's not half alpha (fill it with a 50% opaque rectangle in the “DestOver” blending mode before you pull out the image?). Then set it as the background for the custom button.

Icky. Oh good.

; , .

+1

Source: https://habr.com/ru/post/1759987/


All Articles