/// <summary>
        /// Initializes a new instance of the <see cref="FontAwesomeXamarin.FABarButtonItem"/> class.
        /// </summary>
        /// <param name="icon">An icon from <see cref="FontAwesome.Xamarin.FontAwesome"/></param>
        /// <param name="title">A title to display under the icon</param>
        /// <param name="fontColor">The UIColor for the icon and title</param>
        /// <param name="handler">The event handler for when the button is pressed</param>
        public FABarButtonItem(string icon, string title, UIColor fontColor, EventHandler handler) : base()
        {
            UIView view = new UIView(new RectangleF(0, 0, 32, 32));

            _iconButton = new UIButton(new RectangleF(0, 0, 32, 21))
            {
                Font = FontAwesome.Font(20),
            };
            _iconButton.SetTitleColor(fontColor, UIControlState.Normal);
            _iconButton.TouchUpInside += handler;

            _titleLabel = new UILabel(new RectangleF(0, 18, 32, 10))
            {
                TextColor     = fontColor,
                Font          = UIFont.SystemFontOfSize(10f),
                TextAlignment = UITextAlignment.Center
            };

            this.Title = title;
            this.Icon  = icon;

            view.Add(_iconButton);
            view.Add(_titleLabel);

            CustomView = view;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FontAwesomeXamarin.FABarButtonItem"/> class.
        /// </summary>
        /// <param name="icon">An icon from <see cref="FontAwesome.Xamarin.FontAwesome"/></param>
        /// <param name="title">A title to display under the icon</param>
        /// <param name="fontColor">The UIColor for the icon and title</param>
        /// <param name="handler">The event handler for when the button is pressed</param>
        public FABarButtonItem(string icon, string title, UIColor fontColor, EventHandler handler) : base()
        {
            UIView view = new UIView(new CGRect(2, 0, 56, 32));

            view.AddGestureRecognizer(new UITapGestureRecognizer(() => {
                handler(this, null);
            }));

            _iconButton = new UIButton(new CGRect(14, 0, 32, 21))
            {
                Font = FontAwesome.Font(20),
            };
            _iconButton.SetTitleColor(fontColor, UIControlState.Normal);
            _iconButton.AddGestureRecognizer(new UITapGestureRecognizer(() => {
                handler(this, null);
            }));

            _iconLabel = new UILabel(new CGRect(0, 22, 56, 10))
            {
                TextColor     = fontColor,
                Font          = UIFont.SystemFontOfSize(10f),
                TextAlignment = UITextAlignment.Center
            };
            _iconLabel.AddGestureRecognizer(new UITapGestureRecognizer(() => {
                handler(this, null);
            }));

            this.IconText = title;
            this.Icon     = icon;

            view.Add(_iconButton);
            view.Add(_iconLabel);

            CustomView = view;
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FontAwesome.Xamarin.FABarButtonItem"/> class.
        /// Use the CustomView property to access the button that we create with the new icon
        /// </summary>
        /// <param name="icon">An icon from <see cref="FontAwesome.Xamarin.FontAwesome"/></param>
        /// <param name="fontColor">The UIColor for the icon and title</param>
        /// <param name="handler">The event handler for when the button is pressed</param>
        public FABarButtonItem(string icon, UIColor fontColor, EventHandler handler) : base()
        {
            _iconButton = new UIButton(new CGRect(0, 0, 32, 32))
            {
                Font = FontAwesome.Font(25)
            };
            _iconButton.SetTitleColor(fontColor, UIControlState.Normal);
            _iconButton.TouchUpInside += handler;

            this.Icon  = icon;
            CustomView = _iconButton;
        }