Example #1
0
        public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath)
        {
            var cell = collectionView.DequeueReusableCell(TabCollectionCell.cellIdentifier(), indexPath) as TabCollectionCell;

            configureCell(cell, indexPath: indexPath, tabView);
            return(cell);
        }
Example #2
0
        public TabView(bool _isInfinity, TabPageOption _option) : base(CGRect.Empty)
        {
            option     = _option;
            isInfinity = _isInfinity;
            NSBundle.FromClass(new ObjCRuntime.Class(typeof(TabView))).LoadNib(nameof(TabView), this, null);
            AddSubview(contentView);
            contentView.BackgroundColor = option.tabBackgroundColor.ColorWithAlpha(option.tabBarAlpha);

            var top    = NSLayoutConstraint.Create(contentView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1.0f, 0.0f);
            var left   = NSLayoutConstraint.Create(contentView, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, this, NSLayoutAttribute.Leading, 1.0f, 0.0f);
            var bottom = NSLayoutConstraint.Create(this, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, contentView, NSLayoutAttribute.Bottom, 1.0f, 0.0f);
            var right  = NSLayoutConstraint.Create(this, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, contentView, NSLayoutAttribute.Trailing, 1.0f, 0.0f);

            contentView.TranslatesAutoresizingMaskIntoConstraints = false;
            this.AddConstraints(new NSLayoutConstraint[] { top, left, bottom, right });

            var bundle = NSBundle.FromClass(new ObjCRuntime.Class(typeof(TabView)));
            var nib    = UINib.FromName(TabCollectionCell.cellIdentifier(), bundle);

            collectionView.RegisterNibForCell(nib, TabCollectionCell.cellIdentifier());
            cellForSize = nib.Instantiate(null, null).First() as TabCollectionCell;

            collectionView.ScrollsToTop = false;
            collectionView.DataSource   = this;
            collectionView.Delegate     = this;
            //collectionView.SetCollectionViewLayout(this, true);
            collectionView.Delegate = this;

            currentBarView.BackgroundColor          = option.currentColor;
            currentBarViewHeightConstraint.Constant = option.currentBarHeight;

            if (!isInfinity)
            {
                currentBarView.RemoveFromSuperview();
                collectionView.AddSubview(currentBarView);
                collectionView.TranslatesAutoresizingMaskIntoConstraints = false;

                var topOne = NSLayoutConstraint.Create(currentBarView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, collectionView, NSLayoutAttribute.Top, 1.0f,
                                                       option.tabHeight - currentBarViewHeightConstraint.Constant);
                var leftOne = NSLayoutConstraint.Create(currentBarView, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, collectionView, NSLayoutAttribute.Leading, 1.0f, 0.0f);

                currentBarViewLeftConstraint = leftOne;
                collectionView.AddConstraints(new[] { topOne, leftOne });
            }

            bottomBarViewHeightConstraint.Constant = 1.0f / UIScreen.MainScreen.Scale;
        }
Example #3
0
        public void configureCell(TabCollectionCell cell, NSIndexPath indexPath, TabView tabView)
        {
            var fixedIndex = tabView.isInfinity ? indexPath.Item % tabView.pageTabItemsCount : indexPath.Item;

            cell.item      = tabView.pageTabItems[fixedIndex];
            cell.option    = tabView.option;
            cell.isCurrent = fixedIndex == (tabView.currentIndex % tabView.pageTabItemsCount);

            cell.tabItemButtonPressedBlock = (arg1, arg2) =>
            {
                var direction         = UIPageViewControllerNavigationDirection.Forward;
                var pageTabItemsCount = arg1.pageTabItemsCount;
                var currentIndex      = arg1.currentIndex;
                if (arg1.isInfinity)
                {
                    if (indexPath.Item < pageTabItemsCount || indexPath.Item < currentIndex)
                    {
                        direction = UIPageViewControllerNavigationDirection.Reverse;
                    }
                }
                else
                {
                    if (indexPath.Item < currentIndex)
                    {
                        direction = UIPageViewControllerNavigationDirection.Reverse;
                    }
                }

                arg1.pageItemPressedBlock(fixedIndex, direction);

                if (arg2?.isCurrent == false)
                {
                    arg1.updateCollectionViewUserInteractionEnabled(false);
                }

                arg1.updateCurrentIndexForTap((int)indexPath.Item);
            };
        }