Ohad Regev
Ohad Regev

Reputation: 5711

How to Add a Semi Transparent UIView to a UIViewController

Upon a certain user action, I wish to add to my UIViewController another UIView that will be half transparent; i.e. when it loads, the UIViewController view in the back will still be visible in the background, and the new UIView will appear as a layer above it.

The "Half Transparent" UIView should have several images and buttons in it, so I prefer to create a separated h, m and xib files for it so I can control it.

How should I do that?

Upvotes: 0

Views: 1804

Answers (2)

Rog
Rog

Reputation: 18670

  1. Subclass UIView, create the nib file
  2. Change the nib class to your custom subclass name
  3. Change the file owner to become your view controller
  4. In your view controller, declare a @property for the custom view using IBOutlet
  5. Select the nib, drag from the file owner to the custom view and connect the outlet
  6. In your button action, when you are ready to load the view, use

[[NSBundle mainBundle] loadNibNamed:@"NibName" owner:self options:nil];

Once this is done, your custom will be loaded from the nib and assigned to the property you declared.

Upvotes: 2

Shehzad Bilal
Shehzad Bilal

Reputation: 2523

Try this:

UIView *view = [[UIView alloc] init];
[view setAlpha:0.5];
[mainview addSubview:view]

Upvotes: 4

Related Questions