gpt4 book ai didi

c# - 将 UIBarButtonItem 添加到 Xamarin IOS 中的导航栏

转载 作者:可可西里 更新时间:2023-11-01 04:25:12 26 4
gpt4 key购买 nike

如何将自定义 UIBarButtonItem 添加到导航栏右侧。

public UIBarButtonItem btn_Cart {get; set;}

public DetailedController (){
string buttonTitle = "One";
btn_Cart = new UIBarButtonItem (buttonTitle, UIBarButtonItemStyle.Bordered, null);
btn_Cart.Clicked += (s, e) => { new UIAlertView ("click!", "btnOne clicked", null, "OK", null).Show ();
};

}

public override void ViewDidLoad (){
base.ViewDidLoad ();
// Added btn_Cart to RightSide Of Naviation Bar.
this.NavigationItem.SetRightBarButtonItem (btn_Cart, true);
}

它没有添加到 navigationItem。

如果我将代码更改为

public override void ViewDidLoad (){
this.NavigationItem.SetRightBarButtonItem(
new UIBarButtonItem(UIImage.FromBundle ("Image.png")
, UIBarButtonItemStyle.Plain
, (sender,args) => {
new UIAlertView ("click!", "btnOne clicked", null, "OK", null).Show ();
})
, true);
}

//添加到右侧的 NavigationItem。

public class DetailedTabBarController : UITabBarController {

public override void ViewDidLoad (){
base.ViewDidLoad ();
this.NavigationItem.SetRightBarButtonItem(
new UIBarButtonItem(UIImage.FromBundle ("/Images/Image.png"),
UIBarButtonItemStyle.Plain,
(sender,args) => {
Console.WriteLine("Do Some Action!");
}), true);
}
}

我不想这样添加。

谁能建议我将 UIBarButtonItem 添加到右侧的 NavigationItem。@全部提前致谢

最佳答案

首先创建一个 UIBarButtonItem。然后将其添加到 NavigationItem。这是示例代码

UIBarButtonItem btn = new UIBarButtonItem ();
btn.Image = UIImage.FromFile("Image.gif");
btn.Clicked += (sender , e)=>{System.Diagnostics.Debug.WriteLine("Button tap");};
NavigationItem.RightBarButtonItem = btn;

关于c# - 将 UIBarButtonItem 添加到 Xamarin IOS 中的导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25622434/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com