void OpenOptionView(object sender, EventArgs ea)
        {
            optionVisible = true;

            if (!Utility.IsIPad)
            {
                if (!showOptions)
                {
                    this.ShowOptionView();
                }
                else
                {
                    this.HideOptionView();
                }

                showOptions = !showOptions;
            }
            else
            {
                //iPad view, present PopOver
                OptionViewController optionController = new OptionViewController();
                optionController.OptionView = optionView;

                UIPopoverController popover = new UIPopoverController(optionController);
                popover.SetPopoverContentSize(new CGSize(320.0, 400.0), true);

                UIBarButtonItem barbtn = sender as UIBarButtonItem;
                UIView          view   = barbtn.ValueForKey(new NSString("view")) as UIView;
                CGRect          frame  = new CGRect(this.View.Frame.Width - view.Frame.Width, view.Frame.Y + 23, view.Frame.Width, view.Frame.Height);

                popover.PresentFromRect(frame, this.View, UIPopoverArrowDirection.Up, true);
            }
        }
Ejemplo n.º 2
0
        // Sets a UIBarButtonItem as target
        public void SetTargetView(UIBarButtonItem barButtonItem)
        {
            var view = (barButtonItem.ValueForKey(new NSString("view")) as UIView)?.Subviews?.FirstOrDefault();

            if (view != null)
            {
                _targetView = view;
            }
        }
        /// Sets a UIBarButtonItem as target
        public static void SetTargetView(this MaterialShowcase materialShowcase, UIBarButtonItem barButtonItem)
        {
            var view = barButtonItem.ValueForKey(new NSString("view"));

            if (view != null && view is UIView)
            {
                materialShowcase.targetView = ((UIView)view).Subviews.First();
            }
            materialShowcase.backgroundPromptColor = UINavigationBar.Appearance.TintColor;
        }
 public static UIView PlainView(this UIBarButtonItem barItem)
 {
     return(barItem.ValueForKey(new NSString("view")) as UIView);
 }
        public static void AddBadge(this UIBarButtonItem barButtonItem, string text, UIColor backgroundColor, UIColor textColor, bool filled = true, float fontSize = 11.0f)
        {
            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            CGPoint offset = CGPoint.Empty;

            if (backgroundColor == null)
            {
                backgroundColor = UIColor.Red;
            }

            var font = UIFont.SystemFontOfSize(fontSize);

            if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
            {
                font = UIFont.MonospacedDigitSystemFontOfSize(fontSize, UIFontWeight.Regular);
            }

            var view   = barButtonItem.ValueForKey(new NSString(@"view")) as UIView;
            var bLayer = GetBadgeLayer(barButtonItem);

            bLayer?.RemoveFromSuperLayer();

            var badgeSize = text.StringSize(font);

            var height = badgeSize.Height;
            var width  = badgeSize.Width + 2; /* padding */

            //make sure we have at least a circle
            if (width < height)
            {
                width = height;
            }

            //x position is offset from right-hand side
            var x = view.Frame.Width - width + offset.X;

            var badgeFrame = new CGRect(new CGPoint(x: x, y: offset.Y), size: new CGSize(width: width, height: height));

            bLayer = new CAShapeLayer();
            DrawRoundedRect(bLayer, badgeFrame, 7.0f, backgroundColor, filled);
            view.Layer.AddSublayer(bLayer);

            // Initialiaze Badge's label
            var label = new CATextLayer
            {
                String            = text,
                TextAlignmentMode = CATextLayerAlignmentMode.Center,
                FontSize          = font.PointSize,
                Frame             = badgeFrame,
                ForegroundColor   = filled ? textColor.CGColor : UIColor.White.CGColor,
                BackgroundColor   = UIColor.Clear.CGColor,
                ContentsScale     = UIScreen.MainScreen.Scale
            };

            label.SetFont(CGFont.CreateWithFontName(font.Name));
            bLayer.AddSublayer(label);

            // Save Badge as UIBarButtonItem property
            objc_setAssociatedObject(barButtonItem.Handle, BadgeKey.Handle, bLayer.Handle, AssociationPolicy.RETAIN_NONATOMIC);
        }
 public static UIView UserInfoGetView(this UIBarButtonItem item)
 {
     return(item.ValueForKey(new NSString("view")) as UIView);
 }