【问题标题】:Xamarin iOS - Background image does not fill page on iOS TabletsXamarin iOS - 背景图像不会填满 iOS 平板电脑上的页面
【发布时间】:2020-07-06 15:05:52
【问题描述】:

我有一张图片用于填充登录页面的背景。

Android 手机 - 工作正常

Android 平板电脑 - 工作正常

iOS 手机 - 工作正常

iOS 平板电脑 - 不会一直延伸(见图 - 右侧的深绿色区域)

代码很简单:

<ContentPage
    ...
    BackgroundImageSource="GradientBackground.png">

有谁知道如何解决或解决此问题?

【问题讨论】:

  • 平板的图片尺寸是多少?
  • 我目前正在尝试调整它的大小。但是当我这样做时,我遇到了另一个错误... System.IO.FileNotFoundException:找不到文件'/Users/MyUser/Library/Caches/Xamarin/mtbs/builds/MyApp.Mobile.iOS/9680b637e2cb8a8a2e2c4e64a133d0c0/obj/iPhoneSimulator /Debug/optimized/GradientBackground.png'
  • 使用属性窗口将文件复制为较新的文件。我认为文件没有被复制。
  • 不设置 contentpage 背景图像,而是将外部 Grid 放置到现有控件并将图像放在那里。并设置 Aspect="AspectFill"

标签: xamarin xamarin.ios


【解决方案1】:

但是当我这样做时,我遇到了另一个错误... System.IO.FileNotFoundException: 找不到文件...

尝试清理/重建您的项目。然后重新添加图片。

如果你在 Xamarin.forms 项目中将图片设置为Embedded images,则图片需要设置为Build Action: EmbeddedResource

如果问题仍然存在,请尝试使用BackgroundImageSource自行设置backgroundImage:

<ContentPage.Content>
        <Grid>

            <Image Source="BackGroundImage.jpg" 
                   Aspect="AspectFill"
                   />

            <!-- Place your layouts and controls here, for example-->

        </Grid>

</ContentPage.Content>

【讨论】:

  • 解决了,谢谢。我之前尝试过类似的东西,但由于某些其他原因它不起作用。顺便说一句,找不到图像的问题是通过在VS中打开图像,单击属性并设置为32bpp(该字段已变为空白??)
猜你喜欢
  • 2018-10-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-01
  • 1970-01-01
  • 2013-01-14
相关资源
最近更新 更多