在我的 Xamarin iOS 應用程式中,我試圖隱藏頂部邊框并更改 TabbedPage 的字體系列。對于 Xamarin 版本 5.0.0.2021,它作業正常。但是,當我將 Xamarin 版本更新到 5.0.0.2244 時,它似乎不起作用?這里一定有什么不尋常的地方。這就是我更改字體系列和邊框頂部 TabbedPage 的方式:
我的標簽頁渲染器
更改圖示大小、字體大小、字體系列... TabbedPage
[assembly: ExportRenderer(typeof(TabbedPage), typeof(MyTabbedPageRenderer))]
....
public class MyTabbedPageRenderer : TabbedRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
TabBar.TintColor = UIColor.Gray;
TabBar.BarTintColor = UIColor.White;
TabBar.BackgroundColor = UIColor.White;
}
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
if (TabBar?.Items == null)
return;
foreach (var item in TabBar.Items)
{
item.Image = ScalingImageToSize(item.Image, new CGSize(30, 30)); // set the size here as you want
}
var tabs = Element as TabbedPage;
if (tabs != null)
{
for (int i = 0; i < TabBar.Items.Length; i )
{
UpdateTabBarItem(TabBar.Items[i]);
}
}
}
private void UpdateTabBarItem(UITabBarItem item)
{
if (item == null)
return;
// Set the font for the title.
item.SetTitleTextAttributes(new UITextAttributes() { Font = UIFont.FromName("Quicksand Regular", 12), TextColor = Color.FromHex("#808080").ToUIColor() }, UIControlState.Normal);
item.SetTitleTextAttributes(new UITextAttributes() { Font = UIFont.FromName("Quicksand Regular", 13), TextColor = Color.FromHex("#00AA13").ToUIColor() }, UIControlState.Selected);
}
...
}
移除邊框頂部 TabbedPage
應用程式委托
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
UITabBar.Appearance.BackgroundImage = new UIImage();
UITabBar.Appearance.ShadowImage = new UIImage();
UITabBar.Appearance.SelectedImageTintColor = UIColor.FromRGB(0, 170, 19);
LoadApplication(new App());
}
我嘗試重建專案,重新啟動所有內容,但它似乎不適用于 Xamarin 版本 5.0.0.2244。請求幫忙。謝謝。
uj5u.com熱心網友回復:
iOS 15 有一些 api 的變化,所以我們需要改變 .
去除邊框頂部
TabBar.ClipsToBounds = true;
更改專案的字體和文本顏色
private void UpdateTabBarItem(UITabBarItem item)
{
if (item == null) return;
if(UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
{
UITabBarAppearance app = new UITabBarAppearance();
app.ConfigureWithOpaqueBackground();
app.BackgroundColor = UIColor.Clear;
app.StackedLayoutAppearance.Normal.TitleTextAttributes = new UIStringAttributes() { Font = UIFont.FromName("GillSans-UltraBold", 12), ForegroundColor = Color.FromHex("#00FF00").ToUIColor() };
app.StackedLayoutAppearance.Selected.TitleTextAttributes = new UIStringAttributes() { Font = UIFont.FromName("GillSans-UltraBold", 20), ForegroundColor = Color.FromHex("#FF0000").ToUIColor() };
item.StandardAppearance = app;
if (UIDevice.CurrentDevice.CheckSystemVersion(15, 0))
{
item.ScrollEdgeAppearance = item.StandardAppearance;
}
}
}
在我這邊測驗過,作業正常。
參考
https://stackoverflow.com/a/69361301/8187800。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/382422.html
標籤:沙马林
