Xamarin Forms IconImageSource:
在 Android 工具列上正確顯示影像,在 iOS 上顯示白色影像。我怎樣才能解決這個問題?我將檔案添加到資源檔案夾并將構建操作設定為 BundleResource。
如果我將檔案名更改為非現有檔案,則根本不顯示影像。我嘗試將擴展名更改為 JPG,結果相同,還顯示了白色影像。
我使用了這個代碼片段。
ToolbarItem toolbarItemSearch = new ToolbarItem { IconImageSource = ImageSource.FromFile("searchIcon.png") };
ToolbarItems.Add(toolbarItemSearch);

uj5u.com熱心網友回復:
iOSToolbarItems默認有著色,顏色為 blue/white 。
為了解決這個問題,我們需要創建一個自定義渲染器NavigationPage,并將 設定TintColor 為透明,并將影像設定為另一種渲染模式。
示例代碼
[assembly: ExportRenderer(typeof(NavigationPage), typeof(MyRenderer))]
namespace FormsApp.iOS
{
class MyRenderer : NavigationRenderer
{
public override void PushViewController(UIViewController viewController, bool animated)
{
base.PushViewController(viewController, animated);
var currentPage = (this.Element as Xamarin.Forms.NavigationPage)?.CurrentPage;
if (this.NavigationBar == null || currentPage == null)
return;
var buttonItems = TopViewController.NavigationItem.RightBarButtonItems;
foreach (var button in buttonItems)
{
if(button.Image != null){
button.Image = button.Image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
button.TintColor = UIColor.Clear;
}
}
}
}
}
參考

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/325261.html
標籤:沙马林
上一篇:Python函式
