public ButtonBarPagerTabStripViewController()
        {
            Delegate   = this;
            DataSource = this;
            Func <IndicatorInfo, nfloat> widthCallback = GetWidth;

            ButtonBarItemSpec = ButtonBarItemSpec <ButtonBarViewCell> .Create(widthCallback, "ButtonCell", NSBundle.FromClass(new ObjCRuntime.Class(typeof(ButtonBarViewCell))));
        }
        public ButtonBarPagerTabStripViewController(string nibName, NSBundle bundle) : base(nibName, bundle)
        {
            Delegate   = this;
            DataSource = this;
            Func <IndicatorInfo, nfloat> widthCallback = GetWidth;

            ButtonBarItemSpec = ButtonBarItemSpec <ButtonBarViewCell> .Create(widthCallback, "ButtonCell", null);
        }
        public ButtonBarPagerTabStripViewController(NSCoder coder) : base(coder)
        {
            Delegate   = this;
            DataSource = this;
            Func <IndicatorInfo, nfloat> widthCallback = GetWidth;

            ButtonBarItemSpec = ButtonBarItemSpec <ButtonBarViewCell> .Create(widthCallback, "ButtonCell", null);
        }
        public static ButtonBarItemSpec <ButtonBarViewCell> Create(Func <IndicatorInfo, nfloat> widthCallback, string nibName = null, NSBundle bundle = null)
        {
            ButtonBarItemSpec <ButtonBarViewCell> spec = new ButtonBarItemSpec <ButtonBarViewCell>()
            {
                WidthCallback = widthCallback, NibName = nibName, Bundle = bundle
            };

            return(spec);
        }
        public nfloat?[] CalculateWidths()
        {
            var flowLayout    = ButtonBarView.CollectionViewLayout as UICollectionViewFlowLayout;
            var numberOfCells = ViewControllers.Count();

            List <nfloat> minimumCellWidths          = new List <nfloat>();
            nfloat        collectionViewContentWidth = 0;

            foreach (var viewController in ViewControllers)
            {
                var childController = viewController as IIndicatorInfoProvider;
                var indicatorInfo   = childController.IndicatorInfoForPagerTabStrip(this);

                if (ButtonBarItemSpec.NibName == null)
                {
                    nfloat width = width = ButtonBarItemSpec.WidthCallback(indicatorInfo);
                    minimumCellWidths.Add(width);
                    collectionViewContentWidth += width;
                }
                else
                {
                    nfloat width = width = ButtonBarItemSpec.WidthCallback(indicatorInfo);
                    minimumCellWidths.Add(width);
                    collectionViewContentWidth += width;
                }
            }

            var cellSpacingTotal = new nfloat(numberOfCells - 1) * flowLayout.MinimumLineSpacing;

            collectionViewContentWidth += cellSpacingTotal;

            nfloat collectionViewAvailableVisibleWidth = ButtonBarView.Frame.Size.Width - flowLayout.SectionInset.Left - flowLayout.SectionInset.Right;

            if (!Settings.Style.ButtonBarItemsShouldFillAvailiableWidth || collectionViewAvailableVisibleWidth < collectionViewContentWidth)
            {
                return(minimumCellWidths.Select(i => (nfloat?)i).ToList().ToArray());
            }
            else
            {
                var stretchedCellWidthIfAllEqual = (collectionViewAvailableVisibleWidth - cellSpacingTotal) / new nfloat(numberOfCells);
                var generalMinimumCellWidth      = CalculateStretchedCellWidths(minimumCellWidths.ToArray(), suggestedStretchedCellWidth: stretchedCellWidthIfAllEqual, previousNumberOfLargeCells: 0);

                List <nfloat> stretchedCellWidths = new List <nfloat>();
                foreach (nfloat minimumCellWidthValue in minimumCellWidths)
                {
                    var cellWidth = (minimumCellWidthValue > generalMinimumCellWidth) ? minimumCellWidthValue : generalMinimumCellWidth;
                    stretchedCellWidths.Add(cellWidth);
                }

                return(stretchedCellWidths.Select(i => (nfloat?)i).ToList().ToArray());
            }
        }