标签页栏中的图标和标签之间的间距 [英] Spacing between icon and label in tabbedpage bar
问题描述
我有一个 tabbedPage,我在其中为每个标签分配文本和图标,如下所示:
I have a tabbedPage where I'm assigning text and icons for each tab as follows:
this.Children.Add(new SignaturesTab() { Title = "Signature" , Icon
= "sign_new@2x.png" });
this.Children.Add(new PhotosTab() { Title = "Photos", Icon =
"image_new@2x.png" });
在我的 iPhone 上,图标出现在每个标签栏的标签顶部.
On my iPhone, icon appears top of the label in the bar for each tab.
标签渲染器中的代码:
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
TabBar.TintColor = new UIColor(red: 0.23f, green: 0.56f, blue: 0.20f, alpha: 1.0f);
TabBar.UnselectedItemTintColor = new UIColor(red: 0.34f, green: 0.34f, blue: 0.34f, alpha: 1.0f);
}
public override void ViewDidAppear(bool animated)
{
base.ViewDidAppear(animated);
if (TabBar.Items == null) return;
TabBar.SelectedImageTintColor = new UIColor(red: 0.23f, green: 0.56f, blue: 0.20f, alpha: 1.0f);
foreach (var uiTabBarItem in TabBar.Items)
{
var fontSize = new UITextAttributes(){ Font = UIFont.SystemFontOfSize(13)};
uiTabBarItem.SetTitleTextAttributes(fontSize, UIControlState.Normal);
}
}
有没有办法在图标和标签之间以及到边框之间提供间距/边距.
Is there a way to provide spacing/margin between icon and label and to the borders.
谢谢
推荐答案
使用UIOffset和UIEdgeInsets可以修改Title
和TabBarItem
中的 >Image .
Using UIOffset and UIEdgeInsets can modify posittion of Title
and Image
in TabBarItem
.
TabBarItem.TitlePositionAdjustment = new UIOffset(0, 1);
//UIOffset:Represents a position offset. UIOffset(nfloat horizontal, nfloat vertical);
TabBarItem.ImageInsets = new UIEdgeInsets(0, 0, 5, 0);
//Mean: UIEdgeInsets(nfloat top, nfloat left, nfloat bottom, nfloat right);
修改 UIOffset
和 UIEdgeInsets
中的参数以满足您的需要.
Modifying paramaters inside UIOffset
and UIEdgeInsets
to fit your want.
==============================更新==============================
=============================Update==============================
更改标签栏项目图标颜色:
Changing tab bar item icon color :
UITabBar.Appearance.SelectedImageTintColor = UIColor.Yellow;
//selected color ,this will change the whole tabbar item
只需修改四项:
for (int i = 0; i < 4; i++)
{
var fontSize = new UITextAttributes(){ Font = UIFont.SystemFontOfSize(13)};
uiTabBarItem.SetTitleTextAttributes(fontSize, UIControlState.Normal);
uiTabBarItem.TitlePositionAdjustment = new UIOffset(0, 1);
uiTabBarItem.ImageInsets = new UIEdgeInsets(0, 0, 5, 0);
}
这篇关于标签页栏中的图标和标签之间的间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!