我正在使用Xamarin表单并创建标签页。在IOS中我想增加tabbar的高度,所以在tab标题的底部显示一些空格。我该如何设置?
我尝试过以下代码,但没有用。在底部设置保证金的任何其他方式? :
public class BottomTabbedPage : TabbedRenderer
{
private readonly float tabBarHeight = 72f;
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
TabBar.UnselectedItemTintColor = UIColor.FromRGB(208,208,208);
TabBar.BackgroundColor = UIColor.White;
TabBar.Frame = new CGRect(TabBar.Frame.X, TabBar.Frame.Y + (TabBar.Frame.Height - tabBarHeight), TabBar.Frame.Width, tabBarHeight);
}
}
答案 0 :(得分:2)
您应该将以下代码放在事件ViewWillLayoutSubviews()
:
private readonly float tabBarHeight = 72f;
public override void ViewWillLayoutSubviews()
{
base.ViewWillLayoutSubviews();
CGRect tabFrame = TabBar.Frame;
tabFrame.Height = tabBarHeight;
tabFrame.Y = View.Frame.Height - tabBarHeight;
TabBar.Frame = tabFrame;
}
修改强>
如果您想调整图标和标题的位置,请使用:
foreach (UIViewController vc in ViewControllers)
{
//Adjust the title's position
vc.TabBarItem.TitlePositionAdjustment = new UIOffset(0, -36);
//Adjust the icon's position
vc.TabBarItem.ImageInsets = new UIEdgeInsets(-36, 0, 36, 0);
}