Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a semi-transparent view layer above a current view?

Tags:

You've likely seen this before, its become exceedingly popular in consumery chic apps like ScoutMob. I'm trying to implement a 60% transparent view on launch that will cover my home screen, explaining how to use the functions of the home screen and disappears on tap.

I have my entire app completed (it's using .xib's since its from a years ago, but feel free to explain in storyboard format as well, since I will likely reuse this feature in other iOs 5.0+ applications.)

I have no problem making single views, but temporarily layering one on top of another is something I haven't figured out intuitively. I'll continue researching and include any helpful tips I find in case other people are trying to do the same thing.

like image 781
user Avatar asked Apr 29 '13 16:04

user


1 Answers

// get your window screen size CGRect screenRect = [[UIScreen mainScreen] bounds]; //create a new view with the same size UIView* coverView = [[UIView alloc] initWithFrame:screenRect]; // change the background color to black and the opacity to 0.6 coverView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6]; // add this new view to your main view [self.view addSubview:coverView]; 

when you are done with it , you can remove it :

[coverView removeFromSuperview]; 

Swift3 version:

// get your window screen size let screenRect = UIScreen.main.bounds //create a new view with the same size let coverView = UIView(frame: screenRect) // change the background color to black and the opacity to 0.6 coverView.backgroundColor = UIColor.black.withAlphaComponent(0.6)         // add this new view to your main view self.view.addSubview(coverView) 

to remove it:

coverView.removeFromSuperview() 
like image 146
Rifinio Avatar answered Sep 29 '22 04:09

Rifinio