Ramzi Khahil
Ramzi Khahil

Reputation: 5072

How do I make a view controller be presented with partial transparency?

I have the code below which shows a popup. The popup has a main view which is black, and one subview which is white, and that subview has some labels, button and stuff the user interacts with. I want the surrounding black part to be partially transparent (alpha = 0.7), but the white part inside it to be fully opaque (alpha = 1.0). I could not achieve that, for some reason the value of the parent overrides its child values, and I get either a fully opaque view, or a view where also the labels and buttons are partially transparent.

What Can I do?

The code which shows the popup:

@IBAction func getLocation(sender: AnyObject) {
    var p = PopupViewConrtoller(list: list, callback)
    var x = UINib(nibName: "PickerPopup", bundle: nil).instantiateWithOwner(p, options: nil)
    self.presentViewController(p, animated: false, completion: nil)
    }

Upvotes: 0

Views: 139

Answers (2)

Ramzi Khahil
Ramzi Khahil

Reputation: 5072

I figurred it is impossible to do it the way I was trying to. Rajeev has a good idea, but the best (and the one that apple reviewers will probably approve) is using popovers. This tutorial and this tutorial were helpful.

Upvotes: 0

Rajeev
Rajeev

Reputation: 585

It seems, it is not possible to make main view partially transparent without affecting the subviews added to main view.

What you can do is,

-set mainView background color as clear color
-add one more subview1 to mainView with size same as main view and set the background color as blackColor with desired transparency(alpha=0.7 as in required)
-add your subview2(which is having labels, buttons etc.) to mainView but above subview1 in layer order.

I hope it will help you to achieve what you want.

Upvotes: 1

Related Questions