我的问题是当我将视图作为子视图添加到根视图时。当我更改了根视图的alpha值时,同样在子视图中也发生了。实际上我不需要在子视图中进行更新。是否有任何解决方案要做那样的。
答案 0 :(得分:42)
这将仅更改根视图的alpha,而不是其他
self.view.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.5];
答案 1 :(得分:9)
在@shabbirv的答案基础上,还可以使用IB的颜色选择器
答案 2 :(得分:2)
您需要更改视图的结构。不要在子视图上放置子视图,而是在根视图的ontop上创建一个图层,但仍然将子视图添加到根。更改图层的alpha时,它不会影响子视图。示例结构如下。
您目前的结构:
RootView->Subviews //Changing RootView alpha effects Subviews.
需要的结构:
RootView->View->Subviews(Still Added to RootView) //Changing alpha of Layer doesn't effect subviews.
希望这有帮助。
答案 3 :(得分:1)
This will also solve this by changing root view color by below way, this will not affect the subview.
[rootView setBackgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0.7]];