简体   繁体   English

以编程方式添加的笔尖文件自定义视图是半透明的

[英]nib file custom view added programmatically is semi-transparent

I have a storyboard. 我有一个故事板。 I loaded a custom UIView from nib file to one of my UIViewController programatically. 我以编程方式从nib文件中将自定义UIView加载到我的UIViewController之一。

Opaque and alpha values are checked and 1 respectively. 不透明和alpha值分别检查和为1。

Even though the UIView is semi-transparent. 即使UIView是半透明的。

What would be the problem here? 这是什么问题?

A subview's maximum alpha value is the alpha value of its parent view. 子视图的最大Alpha值是其父视图的Alpha值。

The alpha of the child view is effectively the product of the two alpha values. 子视图的Alpha实际上是两个Alpha值的乘积。 A child with alpha of 1 on a parent with alpha of 0.5 will effectively have a 0.5 alpha. 如果孩子的alpha值为1,而父母的alpha值为0.5,则其有效alpha值为0.5。

If you need to put an opaque subview on a translucent or transparent parent view, there are two approaches. 如果需要在半透明或透明父视图上放置不透明子视图,则有两种方法。

The first approach is to move the would-be parent view to a subview as well so that both views are subviews of the same parent view. 第一种方法是将可能的父视图也移动到子视图,以便两个视图都是同一父视图的子视图。 That parent view is just a clear-background view that acts as a container but has an alpha of 1. 该父视图只是一个背景清晰的视图,它充当容器,但alpha值为1。

The second approach is to make the parent view transparent or translucent while leaving its alpha at 1. This is done by setting its colors to have non-1 alpha values. 第二种方法是使父视图透明或半透明,同时使其alpha保持为1。这是通过将其颜色设置为非1的alpha值来实现的。 For example: 例如:

[UIColor colorWithRed:1 green:0 blue:0 alpha: 0.3];

Rather than just: 不仅仅是:

someView.alpha = 0.3;

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

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