QLPreviewController NavigationBar setTranslucent property not working

I set the custom color in the QLPreviewController navigation bar but the problem is that I want the dark color of the navigation bar in the QLPreviewController even I set the transparent navigation bar property to No But I don’t know why it doesn’t work.

I want it to look like the bottom

enter image description here

but he shows how this image

enter image description here

QLPreviewController *previewer = [[QLPreviewController alloc] init]; // Set data source [previewer setDataSource:self]; [previewer setDelegate:self]; // Which item to preview [previewer setCurrentPreviewItemIndex:index]; [previewer.view addGestureRecognizer:singleTap]; previewer.navigationController.navigationBar.translucent = NO; previewer.navigationController.navigationBar.barTintColor = [UIColor redColor]; self.navigationController.navigationBar.translucent=NO; self.navigationController.navigationBar.barTintColor = [UIColor redColor]; [self.navigationController pushViewController:previewer animated:TRUE ]; 

Even I tried it too, but it doesn't work either

  - (id <QLPreviewItem>)previewController: (QLPreviewController *)controller previewItemAtIndex:(NSInteger)index { // Break the path into it components (filename and extension) // Use the filename (index 0) and the extension (index 1) to get path //lblFileName.text=[strFileName stringByReplacingOccurrencesOfString:@"movefile" withString:@""]; // For navigation bar color and text attributes of navigation bar for (id object in controller.childViewControllers) { if ([object isKindOfClass:[UINavigationController class]]) { UINavigationController *navController = object; navController.navigationBar.translucent=NO; navController.navigationBar.barTintColor = [UIColor redColor];; navController.toolbar.translucent=NO; navController.toolbar.barTintColor=[UIColor redColor];; [navController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil]]; } } NSString *strFilename=[[NSBundle mainBundle]pathForResource:@"final" ofType:@"png"]; return [NSURL fileURLWithPath:strFilename]; } 

Please suggest me where I go wrong. Thanks in advance ...

+7
iphone ios7 uinavigationcontroller uinavigationbar qlpreviewcontroller
source share
3 answers

The main problem is that when you try to set the transparency of the navigation bar, you have not yet pressed the preview controller in the navigation stack. At this point, the preview controller is selected and created, but its view is not loaded or added to the view hierarchy, and the value of previewer.navigationController is zero. The value of self.navigationController not zero at this point, but the translucency property that you set here will be overwritten as a side effect of clicking the preview controller. The easiest way to get the effect you want is to reorder the instructions, for example:

 [self.navigationController pushViewController:previewer animated:YES]; self.navigationController.navigationBar.translucent = NO; 

Please note that with the translucency of the navigation bar set to NO, the previewed content will start under the navigation bar, which is probably not what you want. The easiest way to get around this problem is to set the transparency property after the view controller appears on the screen. You can do this by subclassing QLPreviewController:

 @interface PreviewController : QLPreviewController @end @implementation PreviewController - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; self.navigationController.navigationBar.translucent = NO; } 

Note that it’s more difficult when you present the preview controller in different ways (rather than pushing it on the navigation stack). In this case, there is no navigation controller to access the navigation bar, and you need to rely on the internal hierarchy of the QLPreviewController views. The following code works in iOS7, but may be corrupted in a later version:

 [self presentViewController:previewController animated:YES completion:^{ UIView *view = [[[previewController.view.subviews lastObject] subviews] lastObject]; if ([view isKindOfClass:[UINavigationBar class]]) { ((UINavigationBar *)view).translucent = NO; } }]; 
+8
source share

No need for a subclass. try the following:

  QLPreviewController * ql = [[QLPreviewController alloc] init]; ... [self showViewController:ql sender:self]; ql.navigationController.navigationBar.translucent = NO; ql.edgesForExtendedLayout = UIRectEdgeNone; 

If you want to present it in different ways, just set the previewController to navigationController:

 UINavigationController * navi = [[UINavigationController alloc] initWithRootViewController:ql]; ql.navigationController.navigationBar.translucent = NO; ql.edgesForExtendedLayout = UIRectEdgeNone; [self presentViewController:navi animated:YES completion:nil]; 
+2
source share

Instead of using QLPreviewController, you are not using webview to download pdf. But if you upload pdf to webview, you need to configure its.It buttons are also very similar to QLPreviewController.

  NSURL *targetURL = [NSURL fileURLWithPath:path_pdf]; //path_pdf is pdf path NSURLRequest *request = [NSURLRequest requestWithURL:targetURL]; [webview_pdf loadRequest:request]; 

Well, try it once.

0
source share

All Articles