[英]Customizing QLPreviewController
在自定義QLPreviewController
的外觀時QLPreviewController
。
我們可以通過將QLPreviewController推入導航控制器或將其呈現在ModalViewController中來顯示它。 由於我的navigationController的欄是自定義的(tintColor),所以我推QLPreviewController以保留我的配色方案。 但是當我按下它時,QLPreviewController似乎有一些問題:我需要系統地調用[qlpvc reloadData],以便顯示我的文件。
在iOS [已編輯]中,即使使用reloadData,也不會以推送方式顯示任何內容(實際上,它是以隨機方式顯示的)。 因此,我認為僅使用可靠的Modal方法可能會很有趣。
所以我的意思是我想在ModalViewController中展示我的QLPreviewController。 這樣效果很好,但是我不能自定義viewController的外觀。
例如,在didSelectRowAtIndexPath
如果我這樣做:
(我沒有消息來源,所以如果我做錯了請原諒)
QLPreviewController *qlpvc = [[QLPreviewController alloc] init];
qlpvc.dataSource = self; // Data Source Protocol & methods implemented of course
No need for delegate in my case so //qlpvc.delegate = self;
qlpvc.currentPreviewItemIndex = [indexPath.row];
// The following doesn't work :
[qlpvc.navigationController.navigationBar setTintColor:[UIColor redColor]];
// The following doesn't work too :
[qlpvc.modalViewController.navigationController.navigationBar setTintColor:[UIColor redColor]];
[self presentModalViewController:qlpvc animated:YES];
[qlpvc release];
tl; dr版本:如何管理自定義模態 QLPreviewController的外觀? 尤其是navigationBar的tintColor?
非常感謝。
這行得通,但是我不知道它是否會被Apple拒絕,因為它不是已發布的方法,並且可能會在將來的操作系統版本中中斷。 適用於iOS6。
添加到預覽控制器數據源方法:
- (id <QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
for (id object in controller.childViewControllers)
{
if ([object isKindOfClass:[UINavigationController class]])
{
UINavigationController *navController = object;
navController.navigationBar.tintColor = [UIColor colorWithRed:0.107 green:0.360 blue:0.668 alpha:1.000];
}
}
NSString *pathToPdfDoc = [[NSBundle mainBundle] pathForResource:@"MyPDFFile" ofType:@"pdf"];
return [NSURL fileURLWithPath:pathToPdfDoc];
}
子類QLPreviewController並更改tintColor等在viewDidLoad:
。
如果您試圖在整個應用程序中維護簡單的樣式(如tintColor),則應考慮在許多UIView類上使用UIAppearance選擇器。 下面的示例自定義UINavigationBar的所有實例,包括在QLPreviewController中顯示的實例:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
//..
[self initAppearance];
return YES;
}
-(void)initAppearance{
UINavigationBar* defaultNavigationBar = [UINavigationBar appearance];
UIImage *backgroundImage = [UIImage imageNamed:@"MY_IMAGE.png"]
NSDictionary *defaultNavigationBarDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"Futura-Medium" size:19], NSFontAttributeName,
[UIColor blueColor], UITextAttributeTextColor,
[UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.0f], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0.0f, 2.0f)], UITextAttributeTextShadowOffset,
nil];
defaultNavigationBar.titleTextAttributes = defaultNavigationBarDictionary; //iOS5
//[defaultNavigationBar setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault]; //iOS5
[defaultNavigationBar setBarTintColor:[UIColor redColor]]; //iOS7
[defaultNavigationBar setShadowImage:[[UIImage alloc] init]]; //iOS6, removes shadow
[defaultNavigationBar setTitleVerticalPositionAdjustment:0.0f forBarMetrics:UIBarMetricsDefault]; //iOS5
[defaultNavigationBar setBackIndicatorImage:[UIImage imageNamed:@"BACK_ARROW.png"]]; //iOS7
[defaultNavigationBar setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@"BACK_ARROW.png"]]; //iOS7
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.