开发者

Adding uiview to a uiviewcontroller

I'd like to add a 50x150 uiview that I will be using as a menu, and I want to overlay it on top of my uiviewcontroller. So far what I've done is declare a UIView IBOutlet in the UIViewController class file, and in that UIViewController xib file, I dragged a UIView from the library and hooked it up accordingly. Problem is its not showing up when trying to call it:

menu =开发者_高级运维 [[UIView alloc] initWithFrame:CGRectMake(10,10,50,150)];
//[self.view insertSubview:menu atIndex:0];
[self.view addSubview:menu];
//[self.view bringSubviewToFront:menu];

I've tried different variations as you can see, all suggestions from other posts but I get nothing. Am I going down the wrong path here? What am i missing?


Since you've hooked up the view in Interface Builder, you don't need to alloc a new one. To add it to the view controller's main view, the code should look like this:

[self.view addSubview:self.menu]; // Assuming your IBOutlet is a property called menu.

If you're just using an IBOutlet ivar (not recommended), it should look like this:

[self.view addSubview:menu];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜