如何自定义/设计 UIPopoverController
我正在开发 iPad 应用程序,并且正在使用 UIPopoverControllers。我正处于应用程序需要品牌化和样式化的部分,我想知道如何更改 UIPopoverController 的颜色/色调?标准是深蓝色,但它需要是另一种颜色..
这可能吗?
你好,托马斯
I'm working on an iPad application and I'm using UIPopoverControllers. I'm at the part where the app needs to be branded and styled and i'm wondering how to change the color / tint of the UIPopoverController? Standard is dark blue but it needs to be another color..
is this possible?
Greets, Thomas
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
从iOS 5.0开始,通过子类化抽象类
UIPopoverBackgroundView
并将您的子类分配给popoverBackgroundViewClass
属性一个 href="http://developer.apple.com/library/ios/#documentation/uikit/reference/UIPopoverController_class/Reference/Reference.html">UIPopoverController
实例。不幸的是,没有tintColor
属性,因为弹出窗口需要使用图像作为其箭头和边框,以便在动态调整大小期间实现平滑的动画。您可以在 UIPopoverBackgroundView 类参考This is possible starting in iOS 5.0 by subclassing the abstract class
UIPopoverBackgroundView
and assigning your subclass to thepopoverBackgroundViewClass
property on yourUIPopoverController
instance. Unfortunately there is notintColor
property as the popover needs to use images for it's arrow and border in order to achieve smooth animations during dynamic resizing. You can learn more about how to customize the appearance of a UIPopoverController in the UIPopoverBackgroundView Class Reference目前来说是不可能的。
这就是我所说的“盒中盒”模型。您可以控制框内的框(
UIPopoverController
内的UIViewController
),但您对实际弹出框本身的控制非常有限。除了箭头方向和大小之外,您无法更改太多其他内容。还有模态效果弹出窗口的选项,它在出现时使其他所有内容变暗,但我还没有尝试让它工作。我相信您已经注意到现在还没有
UIPopover
类。您想听到的答案:
如果你真的想设计一个那么糟糕的样式,那就自己写一个吧。这真的没那么难。
您要点击的链接:
Cocoacontrols 是 GitHub 上提供的 iOS 和 OSX 组件的索引,他们有一些弹出窗口的东西。
It's impossible for now.
It's what I call the "Box in a Box" model. You get control of the box inside of the box (the
UIViewController
inside of theUIPopoverController
), but you have very limited control over the actual popover itself. Outside of the arrow direction and the size, you can't change much else. There are also options for a modal effect popover, which dims everything else when it shows up, but I haven't tried to get it working.I'm sure you've noticed there is no
UIPopover
class by now.The answer you want to hear:
If you really want to style one that bad, just write your own. It's really not that hard.
The link you want to click:
Cocoacontrols is an index of iOS and OSX components available on GitHub, they have some popover stuff.
iOS 7 引入了
UIPopoverController
的backgroundColor
属性,该属性影响/包括导航背景颜色以及弹出窗口的箭头。使用示例:
注意 - 截至目前(iOS 7.0.3),在某些情况下(例如使用 colorWithPatternImage: 设置颜色),模拟器(甚至某些设备)不支持颜色。
iOS 7 introduces
backgroundColor
property ofUIPopoverController
which affects/includes the navigation background color as well as arrows of popover.Usage example:
Note - As of now (iOS 7.0.3), in some cases (like set color using colorWithPatternImage:), the simulator (and even some devices) doesn't honor the color.
把我的帽子扔到这里;
我利用 iOS 5+ 中的
UIPopoverBackgroundView
将简单的tintColor
属性添加到UIPopoverController
上。PCPopoverController
:https://github.com/pcperini/PCPopoverControllerThrowing my hat in here;
I've leveraged
UIPopoverBackgroundView
s in iOS 5+ to add a simpletintColor
property ontoUIPopoverController
s.PCPopoverController
: https://github.com/pcperini/PCPopoverController我尝试通过自定义弹出窗口内的视图控制器,然后使用以下代码隐藏弹出窗口边框来欺骗它:
该应用程序实际上仍在开发中,因此我希望其他人对此解决方案发表评论。
I try to trick it by customizing the view controller inside the popover and then hiding the popover border using this code:
The app is actually still in development so I'm hoping other people will comment on this solution.
查看这些利用 UIPopoverBackgroundView 的最新项目
https://github.com/CRedit360/C360PopoverBackgroundView
https://github.com/GiK/GIKPopoverBackgroundView
check out these latest projects leveraging UIPopoverBackgroundView
https://github.com/CRedit360/C360PopoverBackgroundView
https://github.com/GiK/GIKPopoverBackgroundView
从ios 5开始,这是可以完成的,这里是一个库
https://github.com/ddebin/DDPopoverBackgroundView
只要看看文档,这很容易,
祝你好运
from ios 5 onward it is can be done, here is a library
https://github.com/ddebin/DDPopoverBackgroundView
just look at the documentation , and it is quite easy
good luck
您可以使用 Elegant Popover cocoapod 来实现这一点。您可以自定义箭头和弹出框本身的形状和颜色。此外,您还可以向弹出窗口添加彩色边框。
You can use Elegant Popover cocoapod for just that. You can customise shape and colour of the arrow and the popover itself. Also, you can add colourful borders to the popover.
我知道这是一个糟糕的构造答案,但我只是在玩 UIPopoverController 的视图。它们确实存在。
访问它们的唯一方法是从 UIPopovercontroller 中的视图进行访问。
我有一个导航控制器,所以我遵循这个层次结构
这并不完全是最终目标,但它非常接近。
你会发现
the_view_in_the_popover.superview.superview
(如果你没有从导航控制器视图中伸出,可能只是一个超级视图)是一个 UIPopoverView。如果您将其转换为 UIView 并将其视为 UIView,那么您并没有真正违反任何规则。我想这确实取决于苹果。I know this is a lousy constructed answer, but I've just been playing with the UIPopoverController's views. They do exist.
The only way to access them is from your view that is sitting in the UIPopovercontroller.
I have a navigation controller so I follow this hierarchy
This isn't exactly the end goal, but it is really close.
you'll find that
the_view_in_the_popover.superview.superview
(maybe just one superview if you are not reaching out from a navigation controller view) is a UIPopoverView. If you cast it as a UIView and treat it as a UIView you're not really breaking any rules. I guess that is really up to apple though.删除 UIPopoverController 边框:
Remove UIPopoverController border: