public static void SetSideBarMenuItemStyle(this UIButton button, string title, UIImage icon)
 {
     button.ContentEdgeInsets   = new UIEdgeInsets(0, AppTheme.Current.Dimens.Inset2x, 0, AppTheme.Current.Dimens.Inset1x);
     button.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;
     button.SetBackgroundImage(AppTheme.Current.Colors.SideBarMenuItemBackgroundHighlighted.ToImage(), UIControlState.Highlighted);
     button.SetBackgroundImage(AppTheme.Current.Colors.SideBarMenuItemBackgroundSelected.ToImage(), UIControlState.Selected);
     button.SetImage(icon.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate), UIControlState.Normal);
     button.SetTitle(title, UIControlState.Normal);
     button.SetTitleColor(AppTheme.Current.Colors.SideBarMenuItemText, UIControlState.Normal);
     button.TintColor       = AppTheme.Current.Colors.SideBarMenuItemIconBackground;
     button.TitleEdgeInsets = new UIEdgeInsets(0, AppTheme.Current.Dimens.Inset1x, 0, 0);
     button.AddConstraints(button.Height().EqualTo(AppTheme.Current.Dimens.SideBarMenuItemHeight).SetPriority((int)UILayoutPriority.DefaultHigh));
 }
        public void AddBaseElements(UIView mainView)
        {
            titleLabel = new UILabel(RectangleF.Empty);
            titleLabel.TextAlignment = UITextAlignment.Center;

            accessStatus = new UILabel(RectangleF.Empty);
            accessStatus.TextAlignment = UITextAlignment.Center;

            requestAccessButton = UIButton.FromType(UIButtonType.RoundedRect);
            requestAccessButton.TouchUpInside += (s, e) => RequestAccess();

            titleLabel.TranslatesAutoresizingMaskIntoConstraints          = false;
            accessStatus.TranslatesAutoresizingMaskIntoConstraints        = false;
            requestAccessButton.TranslatesAutoresizingMaskIntoConstraints = false;


            // View-level constraints to set constant size values
            titleLabel.AddConstraints(new [] {
                NSLayoutConstraint.Create(titleLabel, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, 14),
                NSLayoutConstraint.Create(titleLabel, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, 180),
            });

            accessStatus.AddConstraints(new[] {
                NSLayoutConstraint.Create(accessStatus, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, 18),
                NSLayoutConstraint.Create(accessStatus, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, 180),
            });

            requestAccessButton.AddConstraints(new[] {
                NSLayoutConstraint.Create(requestAccessButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, 14),
                NSLayoutConstraint.Create(requestAccessButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, 180),
            });
            mainView.AddSubview(titleLabel);
            mainView.AddSubview(accessStatus);
            mainView.AddSubview(requestAccessButton);

            // Container view-level constraints to set the position of each subview
            mainView.AddConstraints(new[] {
                NSLayoutConstraint.Create(titleLabel, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, mainView, NSLayoutAttribute.CenterX, 1, 0),
                NSLayoutConstraint.Create(titleLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, mainView, NSLayoutAttribute.Top, 1, 80),

                NSLayoutConstraint.Create(accessStatus, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, titleLabel, NSLayoutAttribute.CenterX, 1, 0),
                NSLayoutConstraint.Create(accessStatus, NSLayoutAttribute.Top, NSLayoutRelation.Equal, titleLabel, NSLayoutAttribute.Bottom, 1, 40),
                NSLayoutConstraint.Create(requestAccessButton, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, titleLabel, NSLayoutAttribute.CenterX, 1, 0),
                NSLayoutConstraint.Create(requestAccessButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, accessStatus, NSLayoutAttribute.Bottom, 1, 40),
            });
        }
Exemple #3
0
        void SetArrows()
        {
            CleanUpArrows();

            if (Element.ShowArrows)
            {
                var o             = Element.Orientation == CarouselViewOrientation.Horizontal ? "H" : "V";
                var formatOptions = Element.Orientation == CarouselViewOrientation.Horizontal ? NSLayoutFormatOptions.AlignAllCenterY : NSLayoutFormatOptions.AlignAllCenterX;

                prevBtn                 = new UIButton();
                prevBtn.Hidden          = Element.Position == 0 || Element.ItemsSource.GetCount() == 0;
                prevBtn.BackgroundColor = Element.ArrowsBackgroundColor.ToUIColor();
                prevBtn.Alpha           = Element.ArrowsTransparency;
                prevBtn.TranslatesAutoresizingMaskIntoConstraints = false;

                var prevArrow      = new UIImageView();
                var prevArrowImage = new UIImage(Element.Orientation == CarouselViewOrientation.Horizontal ? "Prev.png" : "Up.png");
                prevArrow.Image = prevArrowImage.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate);
                prevArrow.TranslatesAutoresizingMaskIntoConstraints = false;
                prevArrow.TintColor = Element.ArrowsTintColor.ToUIColor();
                prevBtn.AddSubview(prevArrow);

                prevBtn.TouchUpInside += PrevBtn_TouchUpInside;

                var prevViewsDictionary = NSDictionary.FromObjectsAndKeys(new NSObject[] { prevBtn, prevArrow }, new NSObject[] { new NSString("superview"), new NSString("prevArrow") });
                prevBtn.AddConstraints(NSLayoutConstraint.FromVisualFormat("[prevArrow(==17)]", 0, new NSDictionary(), prevViewsDictionary));
                prevBtn.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:[prevArrow(==17)]", 0, new NSDictionary(), prevViewsDictionary));
                prevBtn.AddConstraints(NSLayoutConstraint.FromVisualFormat(o + ":[prevArrow]-(2)-|", 0, new NSDictionary(), prevViewsDictionary));
                prevBtn.AddConstraints(NSLayoutConstraint.FromVisualFormat(o + ":[superview]-(<=1)-[prevArrow]", formatOptions, new NSDictionary(), prevViewsDictionary));

                pageController.View.AddSubview(prevBtn);

                nextBtn                 = new UIButton();
                nextBtn.Hidden          = Element.Position == Element.ItemsSource.GetCount() - 1 || Element.ItemsSource.GetCount() == 0;
                nextBtn.BackgroundColor = Element.ArrowsBackgroundColor.ToUIColor();
                nextBtn.Alpha           = Element.ArrowsTransparency;
                nextBtn.TranslatesAutoresizingMaskIntoConstraints = false;

                var nextArrow      = new UIImageView();
                var nextArrowImage = new UIImage(Element.Orientation == CarouselViewOrientation.Horizontal ? "Next.png" : "Down.png");
                nextArrow.Image = nextArrowImage.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate);
                nextArrow.TranslatesAutoresizingMaskIntoConstraints = false;
                nextArrow.TintColor = Element.ArrowsTintColor.ToUIColor();
                nextBtn.AddSubview(nextArrow);

                nextBtn.TouchUpInside += NextBtn_TouchUpInside;

                var nextViewsDictionary = NSDictionary.FromObjectsAndKeys(new NSObject[] { nextBtn, nextArrow }, new NSObject[] { new NSString("superview"), new NSString("nextArrow") });
                nextBtn.AddConstraints(NSLayoutConstraint.FromVisualFormat("[nextArrow(==17)]", 0, new NSDictionary(), nextViewsDictionary));
                nextBtn.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:[nextArrow(==17)]", 0, new NSDictionary(), nextViewsDictionary));
                nextBtn.AddConstraints(NSLayoutConstraint.FromVisualFormat(o + ":|-(2)-[nextArrow]", 0, new NSDictionary(), nextViewsDictionary));
                nextBtn.AddConstraints(NSLayoutConstraint.FromVisualFormat(o + ":[superview]-(<=1)-[nextArrow]", formatOptions, new NSDictionary(), nextViewsDictionary));

                pageController.View.AddSubview(nextBtn);

                var btnsDictionary = NSDictionary.FromObjectsAndKeys(new NSObject[] { pageController.View, prevBtn, nextBtn }, new NSObject[] { new NSString("superview"), new NSString("prevBtn"), new NSString("nextBtn") });

                var w = Element.Orientation == CarouselViewOrientation.Horizontal ? 20 : 36;
                var h = Element.Orientation == CarouselViewOrientation.Horizontal ? 36 : 20;

                pageController.View.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:[prevBtn(==" + w + ")]", 0, new NSDictionary(), btnsDictionary));
                pageController.View.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:[prevBtn(==" + h + ")]", 0, new NSDictionary(), btnsDictionary));
                pageController.View.AddConstraints(NSLayoutConstraint.FromVisualFormat(o + ":|[prevBtn]", 0, new NSDictionary(), btnsDictionary));
                pageController.View.AddConstraints(NSLayoutConstraint.FromVisualFormat(o + ":[superview]-(<=1)-[prevBtn]", formatOptions, new NSDictionary(), btnsDictionary));

                pageController.View.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:[nextBtn(==" + w + ")]", 0, new NSDictionary(), btnsDictionary));
                pageController.View.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:[nextBtn(==" + h + ")]", 0, new NSDictionary(), btnsDictionary));
                pageController.View.AddConstraints(NSLayoutConstraint.FromVisualFormat(o + ":[nextBtn]|", 0, new NSDictionary(), btnsDictionary));
                pageController.View.AddConstraints(NSLayoutConstraint.FromVisualFormat(o + ":[superview]-(<=1)-[nextBtn]", formatOptions, new NSDictionary(), btnsDictionary));
            }
        }
 static void AddButtonSizeConstraints(UIButton button)
 {
     button.AddConstraints (new[] {
         NSLayoutConstraint.Create (button, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1f, 71f),
         NSLayoutConstraint.Create (button, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1f, 30f)
     });
 }
Exemple #5
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            updateProfilePictureObserver = NSNotificationCenter.DefaultCenter.AddObserver(new NSString("UpdateProfilePicture"), UpdateProfilePicture);
            updateUserNameObserver       = NSNotificationCenter.DefaultCenter.AddObserver(new NSString("UpdateUserName"), UpdateUserName);

            View.BackgroundColor = UIColor.FromRGB(33, 33, 33);

            var scrollView = new UIScrollView(new RectangleF(0, 0, (float)View.Frame.Width, (float)View.Frame.Height));

            profileImageView                     = new UIImageView(new RectangleF(85, 20, 90, 90));
            profileImageView.ContentMode         = UIViewContentMode.ScaleAspectFill;
            profileImageView.Image               = UIImage.FromBundle("Profile");
            profileImageView.Layer.CornerRadius  = (profileImageView.Frame.Width / 2);
            profileImageView.Layer.MasksToBounds = true;

            var tapGestureRecognizer = new UITapGestureRecognizer(this, new ObjCRuntime.Selector("TapProfilePictureSelector:"));

            profileImageView.AddGestureRecognizer(tapGestureRecognizer);
            profileImageView.UserInteractionEnabled = true;

            if (LoginController.userModel.profilePicturePath != null)
            {
                Utils.SetImageFromNSUrlSession(LoginController.userModel.profilePicturePath, profileImageView, this, PictureType.Profile);
            }

            var editProfileButtonImageView = new UIImageView(new RectangleF(220, 20, 24, 24));

            editProfileButtonImageView.ContentMode         = UIViewContentMode.ScaleAspectFill;
            editProfileButtonImageView.Image               = UIImage.FromBundle("EditMenu");
            editProfileButtonImageView.Layer.MasksToBounds = true;
            var tapGestureRecognizerEdit = new UITapGestureRecognizer(this, new ObjCRuntime.Selector("TapProfilePictureSelector:"));

            editProfileButtonImageView.AddGestureRecognizer(tapGestureRecognizerEdit);
            editProfileButtonImageView.UserInteractionEnabled = true;

            userName               = new UILabel(new RectangleF(20, 120, 220, 20));
            userName.Font          = UIFont.SystemFontOfSize(14.0f);
            userName.TextAlignment = UITextAlignment.Center;
            userName.TextColor     = UIColor.White;
            userName.Text          = LoginController.userModel.name;

            var dividerLineView = new UIView(new RectangleF(20, 145, 220, 0.5f));

            dividerLineView.BackgroundColor = UIColor.FromRGB(80, 80, 80);

            var pagesItems     = new MenuPagesModel().MenuItems;
            var pagesTableView = new UITableView(new RectangleF(20, 150, 220, (pagesItems.Count * 40) - 10));

            pagesTableView.ContentInset    = new UIEdgeInsets(0, 20, 0, 0);
            pagesTableView.BackgroundColor = UIColor.Clear;
            pagesTableView.ScrollEnabled   = false;
            new MenuTableViewController(pagesTableView, pagesItems, menuViewController);

            var dividerLineView2 = new UIView(new RectangleF(20, (float)pagesTableView.Frame.Y + (float)pagesTableView.Frame.Height + 15, 220, 0.5f));

            dividerLineView2.BackgroundColor = UIColor.FromRGB(80, 80, 80);

            var filterLabel = new UILabel(new RectangleF(20, (float)dividerLineView2.Frame.Y + 5, 220, 20));

            filterLabel.Font          = UIFont.BoldSystemFontOfSize(12.0f);
            filterLabel.TextAlignment = UITextAlignment.Left;
            filterLabel.TextColor     = UIColor.FromRGB(80, 80, 80);
            filterLabel.Text          = "Filter";

            var filterTipLabel = new UILabel(new RectangleF(20, (float)dividerLineView2.Frame.Y + 5, 220, 20));

            filterTipLabel.Font          = UIFont.BoldSystemFontOfSize(9.0f);
            filterTipLabel.TextAlignment = UITextAlignment.Right;
            filterTipLabel.TextColor     = UIColor.FromRGB(196, 155, 9);
            filterTipLabel.Text          = "You may select more than one";

            var filterItems     = new MenuFilterModel().MenuItems;
            var filterTableView = new UITableView(new RectangleF(26, (float)filterLabel.Frame.Y + 15, 214, filterItems.Count * 40));

            filterTableView.ContentInset    = new UIEdgeInsets(0, 14, 0, 0);
            filterTableView.SeparatorColor  = UIColor.FromRGB(80, 80, 80);
            filterTableView.BackgroundColor = UIColor.Clear;
            filterTableView.ScrollEnabled   = false;
            new MenuTableViewController(filterTableView, filterItems, menuViewController);

            var dividerLineView3 = new UIView(new RectangleF(20, (float)filterTableView.Frame.Y + (float)filterTableView.Frame.Height + 15, 220, 0.5f));

            dividerLineView3.BackgroundColor = UIColor.FromRGB(80, 80, 80);

            #region Hashtag Menu
            //var dividerLineView3 = new UIView(new RectangleF(20, (float)filterTableView.Frame.Y + (float)filterTableView.Frame.Height + 25, 220, 0.5f));
            //dividerLineView3.BackgroundColor = UIColor.Black;

            //var hashtagLabel = new UILabel(new RectangleF(20, (float)dividerLineView3.Frame.Y + 5, 220, 20));
            //hashtagLabel.Font = UIFont.BoldSystemFontOfSize(12.0f);
            //hashtagLabel.TextAlignment = UITextAlignment.Left;
            //hashtagLabel.TextColor = UIColor.Black;
            //hashtagLabel.Text = "Hashtag";

            //var hashtagText = new UITextField(new RectangleF(20, (float)hashtagLabel.Frame.Y + 30, 220, 40));
            //hashtagText.BorderStyle = UITextBorderStyle.Bezel;
            //hashtagText.Placeholder = "inserts tags to filter here";
            #endregion

            #region Logout Button
            var logoutModel = new MenuLogoutModel();

            var logoutButton = new UIButton(new RectangleF(0, (float)dividerLineView3.Frame.Y + 5, (float)View.Frame.Width, 40));
            //logoutButton.BackgroundColor = UIColor.FromRGB(50, 50, 50);
            logoutButton.TouchUpInside += (object sender, EventArgs e) =>
            {
                CredentialsService.DeleteCredentials();
                LoginController.tokenModel = null;
                LoginController.userModel  = null;

                var loginController = menuViewController.Storyboard.InstantiateViewController("LoginNavController");
                if (loginController != null)
                {
                    menuViewController.PresentViewController(loginController, true, null);
                }
            };


            var logoutIcoImageView = new UIImageView();
            logoutIcoImageView.ContentMode         = UIViewContentMode.ScaleAspectFit;
            logoutIcoImageView.Layer.MasksToBounds = true;
            logoutIcoImageView.TranslatesAutoresizingMaskIntoConstraints = false;
            logoutIcoImageView.Image = UIImage.FromBundle(logoutModel.ImageName);

            var logoutTitleLabel = new UILabel();
            logoutTitleLabel.Font      = UIFont.SystemFontOfSize(14);
            logoutTitleLabel.Text      = logoutModel.Title;
            logoutTitleLabel.TextColor = UIColor.White;
            logoutTitleLabel.TranslatesAutoresizingMaskIntoConstraints = false;

            logoutButton.Add(logoutIcoImageView);
            logoutButton.Add(logoutTitleLabel);

            logoutButton.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:|-48-[v0(24)]-20-[v1]-8-|", new NSLayoutFormatOptions(), "v0", logoutIcoImageView, "v1", logoutTitleLabel));
            logoutButton.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:|-8-[v0(24)]", new NSLayoutFormatOptions(), "v0", logoutIcoImageView));
            logoutButton.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:|-10-[v0(24)]", new NSLayoutFormatOptions(), "v0", logoutTitleLabel));
            #endregion

            scrollView.AddSubview(profileImageView);
            scrollView.AddSubview(userName);
            scrollView.AddSubview(editProfileButtonImageView);
            scrollView.AddSubview(dividerLineView);
            scrollView.AddSubview(pagesTableView);
            scrollView.AddSubview(dividerLineView2);
            scrollView.AddSubview(filterLabel);
            scrollView.AddSubview(filterTipLabel);
            scrollView.AddSubview(filterTableView);
            scrollView.AddSubview(dividerLineView3);
            #region Hashtag Menu
            //scrollView.Add(dividerLineView3);
            //scrollView.Add(hashtagLabel);
            //scrollView.Add(hashtagText);
            #endregion
            scrollView.AddSubview(logoutButton);

            var scrollHeight = 20 + profileImageView.Frame.Height + 10 + userName.Frame.Height + 25 + dividerLineView.Frame.Height + 5 + pagesTableView.Frame.Height + 15 +
                               dividerLineView2.Frame.Height + 5 + filterLabel.Frame.Height + 10 + filterTableView.Frame.Height + 5 + dividerLineView3.Frame.Height + 5 +
                               logoutButton.Frame.Height + 40;

            if (scrollHeight > View.Frame.Height)
            {
                scrollView.ContentSize = new CGSize(View.Frame.Width, scrollHeight);
            }
            else
            {
                scrollView.ContentSize = new CGSize(View.Frame.Width, View.Frame.Height);
            }

            View.AddSubview(scrollView);
        }