将 uiview 添加到 uiviewcontroller
我想添加一个 50x150 uiview,我将用作菜单,并且我想将其覆盖在我的 uiviewcontroller 之上。到目前为止,我所做的就是在 UIViewController 类文件中声明一个 UIView IBOutlet,并在该 UIViewController xib 文件中,我从库中拖动一个 UIView 并相应地将其连接起来。问题是它在尝试调用它时没有显示:
menu = [[UIView alloc] initWithFrame:CGRectMake(10,10,50,150)];
//[self.view insertSubview:menu atIndex:0];
[self.view addSubview:menu];
//[self.view bringSubviewToFront:menu];
我已经尝试了不同的变体,如您所见,所有建议都来自其他帖子,但我什么也没得到。我在这里走错路了吗?我缺少什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您已在 Interface Builder 中连接了视图,因此无需分配新视图。要将其添加到视图控制器的主视图,代码应如下所示:
如果您只是使用 IBOutlet ivar (不推荐),它应该如下所示:
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:
If you're just using an IBOutlet ivar (not recommended), it should look like this: