开发者

How can I set a background image for a UILabel and adjust its alpha without changing the transparency of the text?

开发者 https://www.devze.com 2023-01-24 04:50 出处:网络
How can I create a UILabel with a background image and adjust the t开发者_运维百科ransparency (alpha channel) of the background image without changing the transparency of the text?

How can I create a UILabel with a background image and adjust the t开发者_运维百科ransparency (alpha channel) of the background image without changing the transparency of the text?

If there's no easy way to accomplish this within the UILabel object by itself, what about creating a custom UIView object that's composed of a UIImageView and a UILabel, which would allow me to adjust the alpha channel of the image independently of the UILabel's alpha channel? Is that more complicated than it needs to be?

Thanks so much for your wisdom!


A Google codesearch for UIImage, alpha and CGImageRef doesn't turn anything that does exactly what you need, but lots of related code (see for example this). The way I would do follows the same pattern, getting a CGImageRef from your image, drawing it with a composition mode with your transparency, and getting back a UIImage from that using [UIImage imageWithCGImage:].

0

精彩评论

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