這是一個簡單的問題,我問你:如何更改QLPreviewController組件的背景?更改QLPreviewController背景顏色
我用它來呈現PDF文件,但它顯示了滾動視圖模式爲背景 顏色:
[UIColor scrollViewTexturedBackgroundColor]
我想改變背景顏色,但改變視圖的backgroundColor
屬性是沒有幫助。
任何想法?
這是一個簡單的問題,我問你:如何更改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]
並優化上述代碼以滿足您的需求。
這適用於iOS 5.1,但不適用於iOS 6.我認爲他們不再使用UIWebView的實例。不過,即使爲UIView子視圖的每個實例設置背景色也不起作用。 –
在實際問到這裏之前,我嘗試了所有這些東西:子類,改變了負載,改變了確實出現..似乎沒有任何工作。 https://skitch.com/elbryan/eb8g3/ios-simulator –