xcode 透明 UIImage
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11772557/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Transparent UIImage
提问by Obaid
I am creating an iOS application in which I have added a simple UIImage. I want to add the transparency effect in image to show other images behind that main image. Tell me how I can achieve this effect?
我正在创建一个 iOS 应用程序,其中添加了一个简单的 UIImage。我想在图像中添加透明效果以显示该主图像后面的其他图像。告诉我如何才能达到这种效果?
Note:I don't want to change the opacity/alpha of image.
注意:我不想更改图像的不透明度/alpha。
回答by Mick MacCallum
An alpha change is how you alter transparency. In addition to this, you would want to alter this on the view level not on to the UIImage
directly. E.x:
Alpha 更改是您更改透明度的方式。除此之外,您可能希望在视图级别而不是UIImage
直接更改它。前任:
[myImageView setImage:[UIImage imageNamed@"myImage.png"]];
[myImageView setAlpha:0.7f];
回答by Bazinga
how about this:
这个怎么样:
self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f,0.0f,1024.0f,768.0f)];
self.imageView.backgroundColor = [UIColor colorWithRed:255 green:255 blue:255 alpha:0.5];
[self.view addSubview:self.imageView];
or set its alpha
imageView.alpha = 0.5;
But be sure to instantiate the imageView, as property then synthesize.
但是一定要实例化imageView,作为属性然后合成。
回答by meronix
use images in png format with alpha channel in it: alpha channel is the layer that tells how many transparent each pixel is
使用带有 alpha 通道的 png 格式图像:alpha 通道是告诉每个像素有多少透明的层