如何自定义/设计 UIPopoverController

发布于 2024-10-03 23:01:30 字数 156 浏览 0 评论 0原文

我正在开发 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 技术交流群。

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

发布评论

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

评论(10

川水往事 2024-10-10 23:01:30

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 the popoverBackgroundViewClass property on your UIPopoverController instance. Unfortunately there is no tintColor 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

抚笙 2024-10-10 23:01:30

目前来说是不可能的。

这就是我所说的“盒中盒”模型。您可以控制框内的框(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 the UIPopoverController), 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.

慕巷 2024-10-10 23:01:30

iOS 7 引入了 UIPopoverControllerbackgroundColor 属性,该属性影响/包括导航背景颜色以及弹出窗口的箭头。

@property (nonatomic, copy) UIColor *backgroundColor NS_AVAILABLE_IOS(7_0);

使用示例:

    if ([self.popoverVC respondsToSelector:@selector(setBackgroundColor:)]) {   // Check to avoid app crash prior to iOS 7
        self.popoverVC.backgroundColor = [UIColor greenColor];   // [UIColor colorWithPatternImage:@"..."] doesn't reflect the color on simulator but on device it works!
    }

注意 - 截至目前(iOS 7.0.3),在某些情况下(例如使用 colorWithPatternImage: 设置颜色),模拟器(甚至某些设备)不支持颜色。

iOS 7 introduces backgroundColor property of UIPopoverController which affects/includes the navigation background color as well as arrows of popover.

@property (nonatomic, copy) UIColor *backgroundColor NS_AVAILABLE_IOS(7_0);

Usage example:

    if ([self.popoverVC respondsToSelector:@selector(setBackgroundColor:)]) {   // Check to avoid app crash prior to iOS 7
        self.popoverVC.backgroundColor = [UIColor greenColor];   // [UIColor colorWithPatternImage:@"..."] doesn't reflect the color on simulator but on device it works!
    }

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.

情话难免假 2024-10-10 23:01:30

把我的帽子扔到这里;

我利用 iOS 5+ 中的 UIPopoverBackgroundView 将简单的 tintColor 属性添加到 UIPopoverController 上。

PCPopoverControllerhttps://github.com/pcperini/PCPopoverController

Throwing my hat in here;

I've leveraged UIPopoverBackgroundViews in iOS 5+ to add a simple tintColor property onto UIPopoverControllers.

PCPopoverController: https://github.com/pcperini/PCPopoverController

暮色兮凉城 2024-10-10 23:01:30

我尝试通过自定义弹出窗口内的视图控制器,然后使用以下代码隐藏弹出窗口边框来欺骗它:

UIView * border = [[insideViewController.view.superview.superview.superview subviews] objectAtIndex:0];  
border.hidden = YES;

该应用程序实际上仍在开发中,因此我希望其他人对此解决方案发表评论。

I try to trick it by customizing the view controller inside the popover and then hiding the popover border using this code:

UIView * border = [[insideViewController.view.superview.superview.superview subviews] objectAtIndex:0];  
border.hidden = YES;

The app is actually still in development so I'm hoping other people will comment on this solution.

触ぅ动初心 2024-10-10 23:01:30

从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

夏九 2024-10-10 23:01:30

您可以使用 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.

桃扇骨 2024-10-10 23:01:30

我知道这是一个糟糕的构造答案,但我只是在玩 UIPopoverController 的视图。它们确实存在。

访问它们的唯一方法是从 UIPopovercontroller 中的视图进行访问。

我有一个导航控制器,所以我遵循这个层次结构

UIView *test = ((UIView *)[[[self.navigationController.view.superview.superview.subviews objectAtIndex:0] subviews] objectAtIndex:1]);
UIView *test2 = ((UIView *)[[[self.navigationController.view.superview.superview.subviews objectAtIndex:0] subviews] objectAtIndex:1]);
test.backgroundColor = [UIColor greenColor];
test2.backgroundColor = [UIColor greenColor];

这并不完全是最终目标,但它非常接近。

你会发现 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

UIView *test = ((UIView *)[[[self.navigationController.view.superview.superview.subviews objectAtIndex:0] subviews] objectAtIndex:1]);
UIView *test2 = ((UIView *)[[[self.navigationController.view.superview.superview.subviews objectAtIndex:0] subviews] objectAtIndex:1]);
test.backgroundColor = [UIColor greenColor];
test2.backgroundColor = [UIColor greenColor];

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.

手心的温暖 2024-10-10 23:01:30

删除 UIPopoverController 边框:

 NSArray* subviews = ((UIView*)[popupController.contentViewController.view.superview.superview.superview.subviews objectAtIndex:0]).subviews;
for(UIView *subview in subviews){
    [subview removeFromSuperview];
}

Remove UIPopoverController border:

 NSArray* subviews = ((UIView*)[popupController.contentViewController.view.superview.superview.superview.subviews objectAtIndex:0]).subviews;
for(UIView *subview in subviews){
    [subview removeFromSuperview];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文