[英]How can I set a background image for a UILabel and adjust its alpha without changing the transparency of the text?
How can I create a UILabel
with a background image and adjust the transparency (alpha channel) of the background image without changing the transparency of the text? 如何在不更改文本透明度的情况下使用背景图像创建UILabel
并调整背景图像的透明度(alpha通道)?
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? 如果没有简单的方法可以UILabel
在UILabel
对象中完成此操作,那么如何创建一个由UIImageView
和UILabel
组成的自定义UIView
对象,这将允许我独立于UILabel
的alpha调整图像的alpha通道渠道? 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 ). 谷歌对UIImage,alpha和CGImageRef进行的代码搜索并不能完全满足您的需求,但是可以找到许多相关代码(例如,参见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:]
. 我将按照相同的模式进行操作,从图像中获取CGImageRef,使用具有透明度的合成模式进行绘制,然后使用[UIImage imageWithCGImage:]
从中获取UIImage。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.