Esempio n. 1
0
        private UIView CreateActionItem(ActionSheetOption option)
        {
            var view = new UIStackView
            {
                Alignment        = UIStackViewAlignment.Center,
                AutoresizingMask = UIViewAutoresizing.All,
                Distribution     = UIStackViewDistribution.Fill,
                Axis             = UILayoutConstraintAxis.Horizontal
            };

            var tap = new UITapGestureRecognizer(() =>
            {
                try
                {
                    option.Action();
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine("ActionSheet in action (" + option.Text + ") exception: " + e);
                }
                finally
                {
                    this.DismissController();
                }
            });

            view.AddGestureRecognizer(tap);

            if (option.ItemIcon != null)
            {
                var image = UIImage.FromImage(option.ItemIcon.ToNative().CGImage);

                var imageView = new UIImageView
                {
                    Image              = image,
                    BackgroundColor    = UIColor.Clear,
                    ContentMode        = UIViewContentMode.Center,
                    ContentScaleFactor = 2
                };

                imageView.HeightAnchor.ConstraintEqualTo(RowHeight).Active = true;
                imageView.WidthAnchor.ConstraintEqualTo(RowHeight).Active  = true;

                view.AddArrangedSubview(imageView);
            }

            var textView = new UILabel
            {
                Text            = option.Text,
                BackgroundColor = UIColor.Clear,
                TextColor       = MainTextUiColor,
                TextAlignment   = UITextAlignment.Left
            };

            textView.HeightAnchor.ConstraintEqualTo(RowHeight).Active = true;

            view.AddArrangedSubview(textView);

            return(view);
        }