0

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

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

[UIColor scrollViewTexturedBackgroundColor]

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

有任何想法吗?

4

2 回答 2

0

我遇到了类似的问题,最终将子类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]和优化上述代码以满足您的需求。

于 2012-09-01T20:46:57.520 回答
0

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

.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
}
于 2012-06-16T11:58:42.407 回答