ios - Can I make a UIMenu in Xamarin.iOS?
问题描述
I develop in Xamarin.iOS. I would like to create a Pull-Down Menu, which I saw in the Apple Human Interface Guidelines. But I can not see it the official Microsoft documentation.
Is implemented in Xamarin.iOS? If yes, how can I use it?
解决方案
You could check the following code
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,null,(arg)=> {
// do something when you click this item
});
var Action2 = UIAction.Create("Action2", null, null, (arg) => {
// do something when you click this item
});
var Action3 = UIAction.Create("Action3", null, null, (arg) => {
// do something when you click this item
});
var Menus = UIMenu.Create(new UIMenuElement[] {Action1,Action2,Action3 });
return Menus;
}
推荐阅读
- angular - Angular 8 - 来自 websocket 的打字指示器
- python - 我怎样才能只看到使用 shutil.disk_usage("C:") 的存储
- javascript - 当 PostgreSQL 连接不可用时,对 PHP 脚本的 Ajax 调用会减慢整个网页的速度
- bazel - 如何在 Bazel 中强制重建包以测量构建时间
- r - 遍历调查中的变量组 - R
- c# - Asp.net core 2.2 时区问题
- php - SQLite 触发器执行,在 laravel 上抛出错误
- html - html + perl:当用户提交表单时如何显示等待页面/弹出窗口
- python - BeautifulSoup - 具有多个嵌套值的多张卡片
- swift - 使用 SwiftSVG 来自 HTML 数据的 UIImage