1

我有以下 UIActionSheet。如何将它添加到我的顶部导航栏?最好作为最右边的按钮。

var sheet = new UIActionSheet ("");
            sheet.AddButton ("Discard Picture");
            sheet.AddButton ("Pick New Picture");
            sheet.AddButton ("Cancel");
            sheet.CancelButtonIndex = 2;

            // Dummy buttons to preserve the space for the UIImageView
            for (int i = 0; i < 4; i++) {
                sheet.AddButton("");
                sheet.Subviews[i+4].Alpha = 0; // And of course it's better to hide them
            }

            var subView = new UIImageView();
            subView.ContentMode = UIViewContentMode.ScaleAspectFill;
            subView.Frame = new RectangleF(23,185,275,210);

            // Late Steve Jobs loved rounded corners. Let's have some respect for him
            subView.Layer.CornerRadius = 10; 
            subView.Layer.MasksToBounds = true;
            subView.Layer.BorderColor = UIColor.Black.CGColor;
            sheet.AddSubview(subView);

            NavigationController.Add(sheet);
4

1 回答 1

2

您可以使用这些方法显示一个 ActionSheet ShowFrom

特别是,ShowFromToolbar从顶部工具栏按钮显示工作表。

这是一个示例,根据您使用的是平板电脑还是手机,以不同的方式显示工作表:

    void ActionMenu()
    {
        //_actionSheet = new UIActionSheet("");
        UIActionSheet actionSheet = new UIActionSheet (
            "Customer Actions", 
            null, 
            "Cancel", 
            "Delete Customer",
             new string[] {"Change Customer"});

        actionSheet.Style = UIActionSheetStyle.Default;
        actionSheet.Clicked += delegate(object sender, UIButtonEventArgs args) {
            switch (args.ButtonIndex)
            {
                case 0: DeleteCustomer(); break;
                case 1: ChangeCustomer(); break;
            }
        };

        if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
            actionSheet.ShowFromToolbar(NavigationController.Toolbar);
        else
            actionSheet.ShowFrom(NavigationItem.RightBarButtonItem, true);
    }

https://github.com/slodge/MvvmCross-Tutorials/blob/master/Sample%20-%20CustomerManagement/CustomerManagement/CustomerManagement.Touch/Views/CustomerView.cs#L67

于 2013-05-05T06:26:56.447 回答