简体   繁体   English

将带有alpha 1的UIView放在带有alpha 0.5的UIView之上

[英]Putting UIView with alpha 1 on top of UIView with alpha 0.5

I'm trying to have a modular uiview that will be placed on top of another view. 我正在尝试将一个模块化的uiview放置在另一个视图的顶部。 The modular view has an alpha value of 0.5, and appears in the middle of the main view. 模块化视图的alpha值为0.5,显示在主视图的中间。

Now, I would like for text to be rendered on that modular UIView. 现在,我希望在该模块化UIView上呈现文本。 However, whenever I: 但是,每当我:

[modularView addSubview:text]

it looks all hazy. 看起来很朦胧。

How can I make the text tack sharp, but keep the alpha of its parent view at 0.5? 我如何使文字钉清晰,但将其父视图的alpha保持在0.5?

Thanks! 谢谢!

Set the alpha for the background color rather than for the whole view: 为背景颜色而不是整个视图设置Alpha:

[modularView setBackgroundColor:[UIColor colorWithRed:0.0 
                                         green:0.0 
                                          blue:0.0 
                                         alpha:0.5]];

This will allow any subviews to retain full opacity. 这将允许所有子视图保持完全不透明。 The color in my code is black. 我的代码中的颜色是黑色。 Just set the RGB values for whatever color you're wanting. 只需为您想要的任何颜色设置RGB值。

You could also just use a UILabel instead of a UIView and set it's background the same way. 您也可以只使用UILabel代替UIView并以相同方式设置背景。 Then you don't need to add a subview--though I'm not sure what else you have in your modularView view. 然后,您不需要添加子视图-尽管我不确定模块化视图视图中还有什么。

I'm doing the same on a project i'm working on, my "modalview" is on top of a fullscreen image. 我在一个项目上也做同样的事情,我的“ modalview”位于全屏图像的顶部。

My "modalview" has alpha 1.0 and the background color is black with 50% opacity. 我的“ modalview”具有alpha 1.0,背景颜色是黑色,不透明度为50%。

Then the text is white, with default highlight and a dark shadow with 1.0 h and v-offset. 然后,文本为白色,具有默认的突出显示和1.0h和v-offset的深色阴影。

Hope it helps... 希望能帮助到你...

PS: make sure you're adding the text in front of the "modalview", not behind it ;) PS:请确保将文本添加到“ modalview”的前面,而不是后面;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM