FreeSirenety
FreeSirenety

Reputation: 43

iOS adding a top bar as a subview

I am currently working on an app for iPhone where I have an Imageview showing off some images and via swipe I can change the images.

But I'm currently trying to add a subview that will be a top bar, and when the image is touched, it will make this top bar slide down from the top.

The current code I've tried to do this with is:

CGRect frame = CGRectMake(0.0f, 0.0f, self.view.frame.size.width, 60.0f);
UIView *topBar = [[UIView alloc] initWithFrame:frame];
[self.view addSubview:topBar];
[self.view bringSubviewToFront:topBar];

But the topbar won't show up, and I have logs showing that the touches are recognized.

How do I do this, and how do I properly populate the subview with buttons?

Best Regards.

FreeSirenety

Upvotes: 0

Views: 502

Answers (1)

Lefteris
Lefteris

Reputation: 14687

Your topBar has nothing in it, so how can you know it has been added?

CGRect frame = CGRectMake(0.0f, 0.0f, self.view.frame.size.width, 60.0f);
UIView *topBar = [[UIView alloc] initWithFrame:frame];
topBar.backgroundColor = [UIColor redColor];
[self.view addSubview:topBar];

Also you don't need to use the bringSubViewToFront as the view that's gets added as a subview is always the topMost in the view hierarchy!

Upvotes: 2

Related Questions