user2985495
user2985495

Reputation: 89

UIView On Top of Other Views Not Working

I do not understand why my code will not place this custom view on top of the main view. Any suggestions would be great.

Here is my code:

.h

@property (strong, nonatomic) IBOutlet UIView *saved;

.m

self.saved = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];
                    self.saved.backgroundColor = [UIColor colorWithRed:0.0/255 green:102.0/255 blue:153.0/255 alpha:1];
                    [self.view bringSubviewToFront:self.saved];

Upvotes: 0

Views: 53

Answers (1)

JeroValli
JeroValli

Reputation: 569

You need to add as subview [self.view addSubview:self.saved]; before call bringSubviewToFront.

One note: you have declared your property as IBOutlet, this macro is to denote variables that can be referred to in Interface Builder. In case you plan to create and include the subview from the Interface Builder, it is not necessary to initialise and add as subview through code.

Upvotes: 2

Related Questions