为整个 UISplitViewController 添加背景

发布于 2024-11-30 02:11:06 字数 339 浏览 0 评论 0原文

嘿,我想向 UISplitViewController 添加一个背景图像,该图像跨越整个 iPad 屏幕,并且在主视图和详细视图下方可见。

我已经尝试了多种不同的方法,但尚未成功。如果我将它放在 splitView.view 中,它只会覆盖在两个子视图控制器中的所有内容之上。如果我将它放在主视图控制器中,我可以在那里正常执行操作(在其顶部放置 UITableView 等),但它会覆盖详细视图控制器中的所有内容。我尝试的另一条路线是将背景图像放置在它自己的视图控制器中,将整个分割视图控制器放入该视图控制器中,但无论我设置分割视图控制器的 alpha 值,背景仍然是黑色的。

如果有人能指出我让这项工作正常进行,那就太棒了,谢谢!

Hey I want to add a background image to my UISplitViewController that spans the entire iPad screen and is visible underneath both my master and detail views.

I've tried this a number of different ways and have yet to be successful. If I place it in the splitView.view it just overlays on top of everything in both sub-view controllers. If I place it in the master view controller I can do things normally there (place a UITableView on top of it, etc), but it then covers everything in the detail view controller. Another route I tried was to place my background image in it's own view controller the put the entire split view controller inside that view controller, but no matter what I set the alpha of my split view controller the background is still black.

If someone could point me towards getting this working it would be awesome, thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

不必你懂 2024-12-07 02:11:06

成功了!

首先按照 Apple 的示例以编程方式设置 UISplitViewController: http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/iPadControllers/iPadControllers.html

然后添加将 VC 添加到窗口之前的行:

splitVC.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.jpg"]];

Got it working!

First follow along with Apple's example of setting up a UISplitViewController programmatically here: http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/iPadControllers/iPadControllers.html

then add in this line before adding the VC to the window:

splitVC.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.jpg"]];
苏大泽ㄣ 2024-12-07 02:11:06

我刚刚遇到这个问题,我使用的解决方案是将背景图像放在分割视图控制器视图中,然后将其发送到后面。然后它出现在所有其他内容的后面,只要主视图和详细视图具有清晰的背景颜色,您就可以看到背景图像。

因此,如果 self 是 UISplitViewController 的子类,并且 imgView 是包含背景图像的 UIImageView,那么我只需将其添加到 viewDidLoad() 的 end 处(确保它是在我将视图控制器分配给分割视图控制器)

    self.view.addSubview(imgView)
    self.view.sendSubviewToBack(imgView)

I just came across this problem and the solution I've used is to put the background image in the split view controllers view and then send it to the back. Then it appears behind all the other content and as long as the master and detail views have a clear background color you can then see the background image.

So if self is a subclass of UISplitViewController and imgView is a UIImageView that contains the background image then I just added this at the end of the viewDidLoad() (making sure it was after I had assigned view controllers to the split view controller)

    self.view.addSubview(imgView)
    self.view.sendSubviewToBack(imgView)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文