Ios 更改QLPreviewController背景色

Ios 更改QLPreviewController背景色,ios,colors,background,qlpreviewcontroller,Ios,Colors,Background,Qlpreviewcontroller,我问您一个简单的问题:如何更改QLViewController组件的背景 我使用它来显示PDF文件,但它以scrollview模式作为背景显示 颜色: 我想更改背景色,但更改视图的backgroundColor属性没有帮助 有什么想法吗?您需要对其进行子类化并进行更改。大概是这样的: .h文件: #import <QuickLook/QuickLook.h> @interface MyQLPreviewController : QLPreviewController 我遇到了类似

我问您一个简单的问题:如何更改QLViewController组件的背景

我使用它来显示PDF文件,但它以scrollview模式作为背景显示 颜色:

我想更改背景色,但更改视图的backgroundColor属性没有帮助


有什么想法吗?

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

.h文件:

#import <QuickLook/QuickLook.h>

@interface MyQLPreviewController : QLPreviewController

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

- (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];

    }];
}


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

在实际询问之前,我尝试了所有这些内容:子类化、在did加载中更改、在did显示中更改。。似乎什么都不管用。这在iOS 5.1中有效,但在iOS 6中不起作用。我认为他们不再使用UIWebView的实例了。不过,即使为UIView的子视图的每个实例设置背景色也不起作用。
#import "MyQLPreviewController.h"

@implementation MyQLPreviewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor redColor];  // make the change for example
}
- (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];
    }];
}