首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >(Xamarin.Forms IOS) PDF图像不显示

(Xamarin.Forms IOS) PDF图像不显示
EN

Stack Overflow用户
提问于 2021-08-06 11:43:43
回答 1查看 280关注 0票数 1

我有一个用Xamrin表单创建的跨平台应用程序。该应用程序在AndroidUWP中工作得很好。但是在IOS中加载时,图标是不可见的。

例如

代码语言:javascript
复制
<Image >
      <Image.Source>
          <OnPlatform x:TypeArguments="FileImageSource">
              <On Platform="Android" Value="login_icon" />
              <On Platform="UWP" Value="Images/login_icon.png" />
              <On Platform="iOS" Value="login_icon" />
          </OnPlatform>
       </Image.Source>
</Image>   

我以PDF格式在分类目录中添加了所有图像。图像的大小也是正确的。但由于某种原因,图标没有显示。

但是,如果我将这些图像作为.png添加到.png参考资料中,它们就会出现。官方文件说这种方式是不可取的。

编辑:所有的东西在模拟器中看起来都不错,但是当我使用真正的设备进行测试时,这些图标是不可见的。

EN

回答 1

Stack Overflow用户

发布于 2021-08-09 09:01:55

您可以使用CutomRenderer创建一个自定义的webview来显示pdf文件。

代码如下:

代码语言:javascript
复制
    public class CustomWebView : WebView
    {
        public static readonly BindableProperty UriProperty = BindableProperty.Create (propertyName:"Uri",
                returnType:typeof(string),
                declaringType:typeof(CustomWebView),
                defaultValue:default(string));
    
        public string Uri {
            get { return (string)GetValue (UriProperty); }
            set { SetValue (UriProperty, value); }
        }
    }

在监督办中:

代码语言:javascript
复制
   [assembly: ExportRenderer (typeof(CustomWebView), typeof(CustomWebViewRenderer))]
    namespace DisplayPDF.iOS
    {
        public class CustomWebViewRenderer : ViewRenderer<CustomWebView, UIWebView>
        {
            protected override void OnElementChanged (ElementChangedEventArgs<CustomWebView> e)
            {
                base.OnElementChanged (e);
    
                if (Control == null) {
                    SetNativeControl (new UIWebView ());
                }
                if (e.OldElement != null) {
                    // Cleanup
                }
                if (e.NewElement != null) {
                    var customWebView = Element as CustomWebView;
                    string fileName = Path.Combine (NSBundle.MainBundle.BundlePath, string.Format ("Content/{0}", WebUtility.UrlEncode (customWebView.Uri)));
                    Control.LoadRequest (new NSUrlRequest (new NSUrl (fileName, false)));
                    Control.ScalesPageToFit = true;
                }
            }
        }
    }

以下是有关自定义呈现器https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/introduction的文档

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68681043

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档