首页 > 解决方案 > 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?

标签: iosxamarinxamarin.iosmobile-developmentuimenu

解决方案


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;
        }

enter image description here


推荐阅读