更改QLPreviewController背景颜色
问题描述:
这是一个简单的问题,我问你:如何更改QLPreviewController组件的背景?更改QLPreviewController背景颜色
我用它来呈现PDF文件,但它显示了滚动视图模式为背景 颜色:
[UIColor scrollViewTexturedBackgroundColor]
我想改变背景颜色,但改变视图的backgroundColor
属性是没有帮助。
任何想法?
答
您需要继承它并进行更改。事情是这样的:
.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
}
答
我有一个类似的问题,并最终继承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];
}];
}
and
- (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]
并优化上述代码以满足您的需求。
+2
这适用于iOS 5.1,但不适用于iOS 6.我认为他们不再使用UIWebView的实例。不过,即使为UIView子视图的每个实例设置背景色也不起作用。 –
在实际问到这里之前,我尝试了所有这些东西:子类,改变了负载,改变了确实出现..似乎没有任何工作。 https://skitch.com/elbryan/eb8g3/ios-simulator –