mirror of
https://github.com/Nioux/AideDeJeu.git
synced 2025-11-01 16:05:42 +00:00
PdfView iOS à tester
This commit is contained in:
parent
ea0139e2f4
commit
8311919fcf
2 changed files with 62 additions and 0 deletions
|
|
@ -105,6 +105,7 @@
|
|||
</BundleResource>
|
||||
<None Include="Entitlements.plist" />
|
||||
<None Include="Info.plist" />
|
||||
<Compile Include="PdfViewRenderer.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<BundleResource Include="Resources\Fonts\LinLibertine_R.ttf">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
|
|
|
|||
61
AideDeJeu/AideDeJeu.iOS/PdfViewRenderer.cs
Normal file
61
AideDeJeu/AideDeJeu.iOS/PdfViewRenderer.cs
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using AideDeJeu.Views;
|
||||
using Foundation;
|
||||
using UIKit;
|
||||
using Xamarin.Forms.Platform.iOS;
|
||||
|
||||
namespace AideDeJeu.iOS
|
||||
{
|
||||
public class PdfViewRenderer : ViewRenderer<PdfView, UIWebView>
|
||||
{
|
||||
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
base.OnElementPropertyChanged(sender, e);
|
||||
|
||||
if(e.PropertyName == "Uri")
|
||||
{
|
||||
var pdfView = Element as PdfView;
|
||||
|
||||
if (pdfView?.Uri != null)
|
||||
{
|
||||
LoadFile(pdfView.Uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
protected override void OnElementChanged(ElementChangedEventArgs<PdfView> e)
|
||||
{
|
||||
base.OnElementChanged(e);
|
||||
|
||||
if (Control == null)
|
||||
{
|
||||
SetNativeControl(new UIWebView());
|
||||
}
|
||||
if (e.OldElement != null)
|
||||
{
|
||||
// Cleanup
|
||||
}
|
||||
if (e.NewElement != null)
|
||||
{
|
||||
var pdfView = Element as PdfView;
|
||||
|
||||
if (pdfView?.Uri != null)
|
||||
{
|
||||
LoadFile(pdfView.Uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LoadFile(string fileName)
|
||||
{
|
||||
string filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), string.Format("pdf/{0}", WebUtility.UrlEncode(fileName)));
|
||||
Control.LoadRequest(new NSUrlRequest(new NSUrl(filePath, false)));
|
||||
Control.ScalesPageToFit = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue