【问题标题】:Change QLPreviewController background color更改 QLPreviewController 背景颜色
【发布时间】:2012-06-19 06:05:53
【问题描述】:

这是我问你的一个简单问题:如何更改 QLPreviewController 组件的背景?

我用它来呈现 PDF 文件,但它以滚动视图模式作为背景显示 颜色:

[UIColor scrollViewTexturedBackgroundColor]

我想更改背景颜色,但更改视图的 backgroundColor 属性无济于事。

有什么想法吗?

【问题讨论】:

    标签: ios colors background qlpreviewcontroller


    【解决方案1】:

    您需要对其进行子类化并进行更改。像这样的:

    .h 文件:

    #import <QuickLook/QuickLook.h>
    
    @interface MyQLPreviewController : QLPreviewController
    

    .m 文件:

    #import "MyQLPreviewController.h"
    
    @implementation MyQLPreviewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        self.view.backgroundColor = [UIColor redColor];  // make the change for example
    }
    

    【讨论】:

    • 在实际问这里之前,我尝试了所有这些类型的东西:子类化,在确实加载中更改,在确实出现中更改......似乎没有任何工作。 skitch.com/elbryan/eb8g3/ios-simulator
    【解决方案2】:

    我遇到了类似的问题,最终将QLPreviewController 子类化并将以下内容添加到其实现中:

    - (void)viewWillAppear:(BOOL)animated{
        [super viewWillAppear:animated];
    
        //Find webview and set its subviews' background color to white
        [[self.view subviews] enumerateObjectsUsingBlock:^(UIView* view, NSUInteger idx, BOOL *stop) {
    
            [self setSubviewsBackgroundColor:view];
    
        }];
    }
    

    - (void)setSubviewsBackgroundColor:(UIView*)view{
    
        [[view subviews] enumerateObjectsUsingBlock:^(UIView* subview, NSUInteger idx, BOOL *stop) {
    
            if ([subview isKindOfClass:[UIWebView class]]) {
    
                [subview setBackgroundColor:[UIColor whiteColor]];
                [[subview subviews] enumerateObjectsUsingBlock:^(UIView* view, NSUInteger idx, BOOL *stop) {
                    [view setBackgroundColor:[UIColor whiteColor]];
                }];
            }
            else [self setSubviewsBackgroundColor:subview];
        }];
    }
    

    当然,您可能希望更改 [UIColor whiteColor] 并优化上述代码以满足您的需求。

    【讨论】:

    • 这适用于 iOS 5.1 但不适用于 iOS 6。我认为他们不再使用 UIWebView 的实例。尽管如此,即使为 UIView 的子视图的每个实例设置背景颜色也不起作用。
    猜你喜欢
    • 1970-01-01
    • 2013-08-08
    • 1970-01-01
    • 2012-04-21
    • 2017-08-11
    • 2015-10-24
    相关资源
    最近更新 更多