如何解决我可以在 Xamarin.iOS 中制作 UIMenu 吗?
我在 Xamarin.iOS 中开发。我想创建一个下拉菜单,我在 Apple Human Interface Guidelines 中看到了它。 但我看不到它official Microsoft documentation。
是否在 Xamarin.iOS 中实现?如果是,我该如何使用它?
解决方法
您可以检查以下代码
UIButton button = new UIButton()
{
Frame = new CoreGraphics.CGRect(30,100,200,80),Menu = CreateMenu(),};
button.SetTitle("Click Test",UIControlState.Normal);
button.SetTitleColor(UIColor.SystemRedColor,UIControlState.Normal);
button.ShowsMenuAsPrimaryAction = true;
View.AddSubview(button);
UIMenu CreateMenu()
{
//you can set the icon as the second parameter
var Action1 = UIAction.Create("Action1",null,(arg)=> {
// do something when you click this item
});
var Action2 = UIAction.Create("Action2",(arg) => {
// do something when you click this item
});
var Action3 = UIAction.Create("Action3",(arg) => {
// do something when you click this item
});
var Menus = UIMenu.Create(new UIMenuElement[] {Action1,Action2,Action3 });
return Menus;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。