[英]Background image PCL xamarin forms iOS zoomed in
我目前正在處理Xamarin格式的PCL項目,並且因為我完成了Android,所以開始從事iOS實施。 我遇到的問題是視圖的背景圖像被放大了(工具欄上的圖標也是如此),它可能使用了全尺寸圖像,因此我希望使用Aspect=Aspect.AspectFit
類的東西,但是由於我正在使用PCL代碼,我曾使用Background= Height>Width ? <picture_string_portrait> : <picture_string_landscape>
Background= Height>Width ? <picture_string_portrait> : <picture_string_landscape>
,它需要一個字符串。 我似乎無法弄清楚該如何解決+我只能共享默認代碼,因為這是針對我當前正在工作的公司的(所以恐怕也沒有篩選器了)。
這是我的pcl代碼(myview.xaml.cs)的一部分,該代碼在加載時和方向改變時起作用。 在Android中,它可以很好地擴展,但在iOS中則不能。
private void OnSizeChanged(object sender, EventArgs eventArgs)
{
BackgroundImage = Height > Width ? "background_portrait.jpg" : "background_landscape.jpg";
}
如果這是一個菜鳥問題,我深表歉意,但我已經完成了很多與谷歌搜索有關的工作,似乎找不到任何有用的東西。 一個適用於所有人的PCL解決方案將不勝感激。
提前致謝!
ContentPage.BackgroundImage
的問題在於您無法控制其寬高比。 鑒於設備如何具有各種尺寸和形狀,替代解決方案可能對您更好。 通過在ContentPage
使用Image
並使用其Aspect
可以達到相同的結果。 一種方法是使用類似AbsoluteLayout
:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Sample">
<AbsoluteLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<Image AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0, 0, 1, 1" Source="background.png" Aspect="AspectFill"/>
<StackLayout AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0, 0, 1, 1">
// Content
</StackLayout>
</AbsoluteLayout>
</ContentPage>
另一個將是帶有此示例中的RelativeLayout
:
http://dotnetbyexample.blogspot.nl/2015/02/using-full-size-none-stretched.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.