将 uiview 添加到 uiviewcontroller

发布于 2024-09-26 13:40:31 字数 461 浏览 1 评论 0原文

我想添加一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑梦风尘 2024-10-03 13:40:31

由于您已在 Interface Builder 中连接了视图,因此无需分配新视图。要将其添加到视图控制器的主视图,代码应如下所示:

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

如果您只是使用 IBOutlet ivar (不推荐),它应该如下所示:

[self.view addSubview:menu];

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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文