xcode 如何为 iPhone 制作部分透明的 png 图像按钮?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6540751/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 21:23:23  来源:igfitidea点击:

How to make partly transparent png-image buttons for iPhone?

iphonexcodeimagemacostransparent

提问by ragnarius

My iPhone App has custom buttons that display png-images. I like to replace the white color in those images by a transparent color. Is there a tool on the Mac that allows me to do that? (or is there some other way to indicate which color is transparent in xcode?)

我的 iPhone 应用程序具有显示 png 图像的自定义按钮。我喜欢用透明颜色替换这些图像中的白色。Mac 上是否有允许我这样做的工具?(或者是否有其他方法可以指示 xcode 中哪种颜色是透明的?)

采纳答案by Sean Harlow

The Preview application has a mode on its select tool called "Instant Alpha" which eases selection of backgrounds. Once you have your background selected, you can simply press the "Delete" key and that area of the image will be removed. Save it as a PNG with the "Alpha" box checked and you're done.

预览应用程序在其选择工具上有一个名为“Instant Alpha”的模式,可以简化背景的选择。选择背景后,您只需按“删除”键即可删除该图像区域。将它保存为 PNG 并选中“Alpha”框,然后就完成了。

Most other image editing tools, particularly those supporting multiple layers in the image, will also properly support PNG alpha channels. These will likely be easier than using Preview, but they are all third-party and many cost money so you will need to make that decision.

大多数其他图像编辑工具,尤其是那些支持图像多层的工具,也将正确支持 PNG alpha 通道。这些可能比使用预览更容易,但它们都是第三方的,而且很多都需要花钱,因此您需要做出决定。

Please note however that if you are starting from an image with a solid background to which some things have a faded edge that blends in to the background, it is unlikely that you'll be able to remove the background entirely to your satisfaction without cutting in to the actual image.

但是请注意,如果您从具有纯色背景的图像开始,其中某些事物的边缘褪色并与背景融合,则您不太可能在不切入的情况下完全去除背景以令您满意到实际图像。

You may have seen GIF images in the past which were designed to blend in on a white background and had some bright pixels at the edges which stood out and look ugly on darker backgrounds. An image properly saved as PNG or any other format with an alpha channel from the beginning will not have this problem.

您可能在过去看到过 GIF 图像,这些图像旨在融入白色背景,边缘有一些明亮的像素,在较暗的背景下显得很丑陋。从一开始就正确保存为 PNG 或任何其他带有 Alpha 通道的格式的图像不会出现此问题。

回答by Vineesh TP

Just set the image view alpha.

只需设置图像视图 alpha。

- (void)viewDidLoad
{
  [super viewDidLoad];

  self.view.backgroundColor=[UIColor greenColor]; //Set background color

  UIImageView *imgView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"images-4.jpeg"]] ; // Create and initialize imageView 
  imgView.frame=CGRectMake(10, 10, 200,250);// Set frame for imageView
  [self.view addSubview:imgView];
  imgView.alpha=0.1; //Adjust alpha
}

enter image description hereenter image description here

在此处输入图片说明在此处输入图片说明

回答by Kamal Abuqaaud

Start with a png file (use image preview).

从 png 文件开始(使用图像预览)。

You have to go to View > Show Edit Toolbar.

您必须转到“查看”>“显示编辑工具栏”。

Then widen the window so that you can see all of the icons.

然后加宽窗口,以便您可以看到所有图标。

Then click the icon that looks like a magic wand.

然后单击看起来像魔术棒的图标。

And then click and drag on the color you want to erase.

然后单击并拖动要擦除的颜色。