iPhone 11模拟器上的背景图片大小不合适

问题描述 投票:0回答:1

我使用的是Xamarin.Forms 4.6.0,我按照说明把图片暂时放到Assets.xcassets中。

它的工作在iPhone 8+和iPhone8的罚款,但当我尝试在iPhone 11我得到的 this background在我的安卓手机上一切正常。

在我的资产中,我使用的这个背景的尺寸是。

  • 1@ - 375x667
  • 2@ - 750 x 1334
  • 3@ - 1242 x 2208

我发现iPhone 11的屏幕尺寸是1792 x 828?如果是,我需要把这个分辨率放在哪里?我已经在我的资产文件中占据了1@、2@和3@。

ios xamarin xamarin.forms xamarin.ios
1个回答
0
投票

试试这个。


[assembly: ExportRenderer(typeof(YourPage), typeof(CustomPage))]

namespace Your.NameSpace.Project.iOS
{
    public class CustomPage : PageRenderer
    {
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(false);

            UIGraphics.BeginImageContext(this.View.Frame.Size);
            UIImage i = UIImage.FromFile("FileImageBackground.png");
            i = i.Scale(this.View.Frame.Size);

            this.View.BackgroundColor = UIColor.FromPatternImage(i);

        }
    }
}

如果你的整个项目使用背景图片替换 YourPage 与...对抗 Page

© www.soinside.com 2019 - 2024. All rights reserved.