这是我问你的一个简单问题:如何更改 QLPreviewController 组件的背景?
我用它来呈现 PDF 文件,但它以滚动视图模式作为背景颜色显示:
[UIColor scrollViewTexturedBackgroundColor]
我想更改该背景颜色,但更改视图的backgroundColor
属性无济于事。
有任何想法吗?
这是我问你的一个简单问题:如何更改 QLPreviewController 组件的背景?
我用它来呈现 PDF 文件,但它以滚动视图模式作为背景颜色显示:
[UIColor scrollViewTexturedBackgroundColor]
我想更改该背景颜色,但更改视图的backgroundColor
属性无济于事。
有任何想法吗?
我遇到了类似的问题,最终将子类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]
和优化上述代码以满足您的需求。
您需要对其进行子类化并进行更改。像这样的东西:
.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
}