我在Xamarin.iOS的UINavigationBar
右侧添加了带图片的自定义按钮,
但遗憾的是还没有成功。问题是它总是显示一个蓝色背景的按钮。
这是我的代码:
var customBtn = new UIBarButtonItem ();
customBtn.Image = UIImage.FromFile ("home.png");
customBtn.Clicked += (object sender, EventArgs e) =>
{
Console.WriteLine("This button is clicked");
};
NavigationItem.RightBarButtonItem = customBtn;
答案 0 :(得分:0)
认为您需要使用SetRightBarButtonItems
,如此:
var rightButton = new UIButton (UIButtonType.Custom);
rightButton.SetImage (UIImage.FromBundle ("home"), UIControlState.Normal);
rightButton.SetImage (UIImage.FromBundle ("home"), UIControlState.Disabled);
rightButton.Frame = new CGRect (0, 0, 17, 17); // set this to the size of the image
var rightBarButton = new UIBarButtonItem (rightButton);
navItem.SetRightBarButtonItems(new UIBarButtonItem[] {rightBarButton }, false);
rightButton.TouchUpInside += (sender, e) => {
Console.WriteLine("This button is clicked");
};