我想为底部标签创建这种设计
我在 Xamarin.Forms 中工作,并且在 iOS 中面临设计问题。我正在使用 TabbedPage 如下:
<TabbedPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Inika.Views.BottomBar.BottomBarPages"
xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
android:TabbedPage.ToolbarPlacement="Bottom"
android:TabbedPage.BarItemColor="#A9A9A9"
android:TabbedPage.BarSelectedItemColor="Black">
</TabbedPage>
对于这种设计,我创建了“TabbedRenderer”
public class TabbedPageRender_Global : TabbedRenderer
{
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
if (TabBar == null) return;
if (TabBar.Items == null) return;
var tabs = Element as TabbedPage;
//For selected Items
UITabBarItem.Appearance.SetTitleTextAttributes(new UITextAttributes()
{
TextColor = UIColor.FromRGB(255, 255, 255)
},
UIControlState.Selected);
UITabBar.Appearance.SelectedImageTintColor = UIColor.FromRGB(255, 255, 255);
CGSize size = new CGSize(TabBar.Frame.Width / TabBar.Items.Length, TabBar.Frame.Height);
UITabBar.Appearance.SelectionIndicatorImage = imageWithColor(size);
//For unselected Items
TabBar.UnselectedItemTintColor = UIColor.Gray;
base.ViewWillAppear(animated);
}
public UIImage imageWithColor(CGSize size)
{
CGRect rect = new CGRect(0 , 0, size.Width, size.Height);
UIGraphics.BeginImageContext(size);
using (CGContext context = UIGraphics.GetCurrentContext())
{
context.SetFillColor(UIColor.Black.CGColor);
context.FillRect(rect);
}
UIImage image = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
return image;
}
}
iPad截图
它在 iPhone 中看起来很合适,但在所有 iPad 中,它看起来像下图
它从一开始就留下了一些空间。
CGRect rect = new CGRect(0 , 0, size.Width, size.Height);
我应该怎么办?请建议我一些解决方法。
这是 IOS 在 iPad 设备中的本机行为吗?