在 xcode 中设置 alpha 背景图像 iphone 应用程序

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

set alpha background image iphone application in xcode

iphonexcodebackgroundalpha

提问by Martin

I got this:

我懂了:

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.png" ]];

and some other stuff like textfields and stuff on one view.

和其他一些东西,比如文本字段和一个视图上的东西。

I want to set the backgroundimages alpha so that it doesnt distract. but when i do:

我想设置 backgroundimages alpha 以便它不会分散注意力。但是当我这样做时:

self.view.alpha

it sets it for all objects :-(

它为所有对象设置它:-(

and there is no:

并且没有:

self.view.backgroundcolor.alpha

any idea?

任何的想法?

回答by Jon

I worked it out so that you don't need 2 separate views.

我已经解决了,所以你不需要 2 个单独的视图。

    // Make sure your whole view is NOT transparent
    self.view.alpha = 1.0f;
    // Use UIColor to set alpha transparency of just the background view
    self.view.backgroundColor = [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.5f];

Voila!

瞧!

回答by Ole Begemann

That's how it works. To achieve the effect you desire, you need two separate views, one that contains just the background (and has its alphaset), and one with a transparent background and alphaof 1.0 that contains the other controls.

这就是它的工作原理。为了达到你想要的效果,你需要两个单独的视图,一个只包含背景(并有它的alpha集合),一个具有透明背景和alpha包含其他控件的 1.0。