In my application I have used a QLPreviewController to display some pdf files. Everything works fine, but there is an unwanted space in the top of content of QLPreviewController and couldn't find a way to remove it.
This is how I wrote it. (Please note that I am new to Xamarin.iOS and QLPreviewController)
public partial class ReportsViewController : UIViewController
{
public override void ViewDidLoad()
{
base.ViewDidLoad();
//Customize navigation bar for QLPreviewController
if(UIDevice.CurrentDevice.CheckSystemVersion(11, 0)) // There is a bug with barTintColor on QLPreviewController for iOS 11 if you are showing it via presentViewController: animated:
{
var color = UIColor.FromRGB(red: 23, green: 61, blue: 86).CGColor;
var rect = new CGRect(x: 0.0, y: 0.0, width: 1.0, height: 1.0);
var alpha = color.Alpha;
var opaque = alpha == 1;
UIGraphics.BeginImageContextWithOptions(rect.Size, opaque, 0);
var context = UIGraphics.GetCurrentContext();
context.SetFillColor(color);
context.FillRect(rect);
var image = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
UINavigationBar.AppearanceWhenContainedIn(typeof(QLPreviewController)).SetBackgroundImage(image, UIBarMetrics.Default);
}
else // If iOS version is below 11.0
{
UINavigationBar.AppearanceWhenContainedIn(typeof(QLPreviewController)).BarTintColor = UIColor.FromRGBA(red: 255, green: 0, blue: 0, alpha: 1.0f);
}
UINavigationBar.AppearanceWhenContainedIn(typeof(QLPreviewController)).BarStyle = UIBarStyle.Black;
UINavigationBar.AppearanceWhenContainedIn(typeof(QLPreviewController)).TintColor = UIColor.White;
var reportSavedPath = "path to pdf file";
var reportName = "Report name";
var previewController = new QLPreviewController();
var url = new NSUrl(reportSavedPath, true);
var _dataSource = new PreviewControllerSource(this, url, reportName);
previewController.DataSource = _dataSource;
PresentViewController(previewController, true, completionHandler: null);
}
}
public partial class ReportsViewController : UIViewController
{
class PreviewControllerSource : QLPreviewControllerDataSource
{
ReportsViewController _parentClass = null;
NSUrl _url = null;
string _title = null;
public PreviewControllerSource(ReportsViewController parentClass, NSUrl url, string title)
{
_parentClass = parentClass;
_url = url;
_title = title;
}
public override nint PreviewItemCount(QLPreviewController controller)
{
return 1;
}
public override IQLPreviewItem GetPreviewItem(QLPreviewController controller, nint index)
{
return new PreviewItem { title = _title, url = _url };
}
}
public class PreviewItem : QLPreviewItem
{
public string title { get; set; }
public NSUrl url { get; set; }
public override string ItemTitle { get { return title; } }
public override NSUrl ItemUrl { get { return url; } }
}
}
This is how it looks like when the pdf is loaded
Can someone please help me to get this unwanted space removed?