我的选项卡式列表中有三个内容页面,所有页面的底部都有一个可以单击的菜单,并且其中还有一个图标。在 Android 上,图标在 iOS 上看起来大小正好,如下所示:
[![在此处输入图像描述][1]][1]
这是xaml代码:
<ContentPage Title="Abgelehnt"
BackgroundColor="#e1e1e1"
x:Name="tab1_tabbedlist_history"
IconImageSource="icon_cross" >
[1]: /image/oTTST.png
如您所见,我什至没有为它们添加任何尺寸。为什么它们这么大?
This is the tabbed Page:
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:abstractions="clr-namespace:ImageCircle.Forms.Plugin.Abstractions;assembly=ImageCircle.Forms.Plugin"
mc:Ignorable="d"
BackgroundColor="#ffffff"
x:Class="App4.Screens.ScrollViews.Screen_TabbedLists">
<!--Pages can be added as references or inline-->
<ContentPage...>
</TabbedPage>
没有自定义渲染器...
最佳答案
正如 @Jason 所说,最好的方法是遵循 iOS 中图标大小的准则。不过,如果您确实想使用更大尺寸的图像,您可以在 iOS 平台中使用 CustomRenderer 重新设置尺寸。
在 iOS 项目中
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using xxx;
using xxx.iOS;
using CoreGraphics;
[assembly:ExportRenderer(typeof(TabbedPage),typeof(MyTabbedPageRenderer))]
namespace xxx.iOS
{
public class MyTabbedPageRenderer :TabbedRenderer
{
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
foreach (var item in TabBar.Items)
{
item.Image = ScalingImageToSize(item.Image, new CGSize(30, 30)); // set the size here as you want
}
}
public UIImage ScalingImageToSize(UIImage sourceImage, CGSize newSize)
{
if (UIScreen.MainScreen.Scale == 2.0) //@2x iPhone 6 7 8
{
UIGraphics.BeginImageContextWithOptions(newSize, false, 2.0f);
}
else if (UIScreen.MainScreen.Scale == 3.0) //@3x iPhone 6p 7p 8p...
{
UIGraphics.BeginImageContextWithOptions(newSize, false, 3.0f);
}
else
{
UIGraphics.BeginImageContext(newSize);
}
sourceImage.Draw(new CGRect(0, 0, newSize.Width, newSize.Height));
UIImage newImage = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
return newImage;
}
}
}
关于ios - Xamarin.Forms:TabbedPage 图标在 Android 上很好,但在 iOS 上太大,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61911343/