private void LayoutButtons() { if (this.buttons != null) { int numberOfRows = this.layoutHandler.CalculateNumberOfRows(this.buttons.Count()); if (numberOfRows < 1) { throw new InvalidOperationException("The layout handler calculated the number of rows as less than 1."); } foreach (UIView row in this.buttonRows) { row.RemoveFromSuperview(); } this.buttonRows.Clear(); this.buttonHeightConstraints.Clear(); for (int i = 0; i < numberOfRows; i++) { IEnumerable <SegmentedControlItem> itemsForRow = this.layoutHandler.SelectItemsForRow(this.buttons.Select(item => item.Item2), i); IEnumerable <UIButton> buttonsForRow = this.buttons.Where(item => itemsForRow.Contains(item.Item2)).Select(item => item.Item1); this.AddRow(buttonsForRow); } UIView topRow = this.buttonRows.First(); topRow.Anchor(AnchorEdges.Horizontal | AnchorEdges.Top); for (int i = 1; i < this.buttonRows.Count; i++) { UIView currentRow = this.buttonRows[i]; currentRow.Anchor(AnchorEdges.Horizontal); currentRow.AnchorBelow(topRow); topRow = currentRow; } this.buttonRows.Last().Anchor(AnchorEdges.Bottom); } }