public UIScheduleView(ScheduleViewModel viewModel) { this.MaximumZoomScale = 1f; this.MinimumZoomScale = 0.3f; this.ViewForZoomingInScrollView += delegate { return(_mainView); }; this.BackgroundColor = UIColorCompat.SystemBackgroundColor; ViewModel = viewModel; ViewModel.PropertyChanged += new WeakEventHandler <PropertyChangedEventArgs>(ViewModel_PropertyChanged).Handler; _mainView = new UIView() { TranslatesAutoresizingMaskIntoConstraints = false }; this.Add(_mainView); _mainView.ConfigureForMultiDirectionScrolling(this); _timesColumn = new UIView() { TranslatesAutoresizingMaskIntoConstraints = false, BackgroundColor = UIColorCompat.SystemGray4Color }; _mainView.Add(_timesColumn); _timesColumn.StretchHeight(_mainView); _contentColumn = new UIView() { TranslatesAutoresizingMaskIntoConstraints = false }; _mainView.Add(_contentColumn); _contentColumn.StretchHeight(_mainView); _mainView.AddConstraints(NSLayoutConstraint.FromVisualFormat($"H:|[timesColumn][contentColumn]|", NSLayoutFormatOptions.DirectionLeadingToTrailing, null, new NSDictionary( "timesColumn", _timesColumn, "contentColumn", _contentColumn))); // Days row _daysRow = new UIView() { TranslatesAutoresizingMaskIntoConstraints = false, BackgroundColor = UIColorCompat.SystemGray4Color }; _contentColumn.Add(_daysRow); _daysRow.StretchWidth(_contentColumn); // All day items row _allDayItemsRow = new UIView() { TranslatesAutoresizingMaskIntoConstraints = false }; _contentColumn.Add(_allDayItemsRow); _allDayItemsRow.StretchWidth(_contentColumn); // Schedule row _scheduleRow = new UIView() { TranslatesAutoresizingMaskIntoConstraints = false }; _contentColumn.Add(_scheduleRow); _scheduleRow.StretchWidth(_contentColumn); //_daysRow.PinToTop(_contentColumn); //_scheduleRow.StretchHeight(_contentColumn); _contentColumn.AddConstraints(NSLayoutConstraint.FromVisualFormat($"V:|[daysRow][allDayItemsRow][scheduleRow]|", NSLayoutFormatOptions.DirectionLeadingToTrailing, null, new NSDictionary( "daysRow", _daysRow, "allDayItemsRow", _allDayItemsRow, "scheduleRow", _scheduleRow))); // Make scheduleRow be the big one, allDayItemsRow shrink _scheduleRow.SetContentCompressionResistancePriority(501, UILayoutConstraintAxis.Vertical); _allDayItemsRow.SetContentCompressionResistancePriority(499, UILayoutConstraintAxis.Vertical); // Populate days columns UIView prevDayLabel = null; UIView prevAllDayItems = null; UIView prevScheduleColumn = null; for (int i = 0; i < 7; i++) { // Day header var dayLabel = new UILabel() { TranslatesAutoresizingMaskIntoConstraints = false, Font = UIFont.PreferredSubheadline, Lines = 1 }; _daysRow.Add(dayLabel); if (prevDayLabel == null) { dayLabel.PinToLeft(_daysRow, COL_PADDING); } else { dayLabel.SetToRightOf(prevDayLabel, _daysRow, COL_PADDING); } dayLabel.SetWidth(COL_WIDTH - COL_PADDING); dayLabel.StretchHeight(_daysRow, top: 3, bottom: 3); _dayLabels[i] = dayLabel; prevDayLabel = dayLabel; // All day items var allDayItemsStackView = new UIStackView() { TranslatesAutoresizingMaskIntoConstraints = false, Axis = UILayoutConstraintAxis.Vertical, Spacing = 1 }; { var itemsSource = new BareUIStackViewItemsSourceAdapter(allDayItemsStackView, CreateAllDayItemView); _allDayItemSourceAdapters[i] = itemsSource; } UIView allDayItemsView = allDayItemsStackView; // Have to place the stack view in a view since background doesn't render on stack view itself allDayItemsView = new UIView() { TranslatesAutoresizingMaskIntoConstraints = false, BackgroundColor = UIColorCompat.SecondarySystemBackgroundColor }; allDayItemsView.Add(allDayItemsStackView); allDayItemsStackView.StretchWidthAndHeight(allDayItemsView, right: 1); if (i % 2 != 0) { // Alternate light and dark allDayItemsView.BackgroundColor = UIColorCompat.SecondarySystemBackgroundColor; } else { allDayItemsView.BackgroundColor = UIColorCompat.SystemBackgroundColor; } _allDayItemsRow.Add(allDayItemsView); if (prevAllDayItems == null) { allDayItemsView.PinToLeft(_allDayItemsRow); } else { allDayItemsView.SetToRightOf(prevAllDayItems, _allDayItemsRow); } allDayItemsView.SetWidth(COL_WIDTH); allDayItemsView.StretchHeight(_allDayItemsRow); prevAllDayItems = allDayItemsView; // Schedule column var scheduleColumn = new UIControl() { TranslatesAutoresizingMaskIntoConstraints = false }; if (i % 2 != 0) { // Alternate light and dark scheduleColumn.BackgroundColor = UIColorCompat.SecondarySystemBackgroundColor; } _scheduleRow.Add(scheduleColumn); if (prevScheduleColumn == null) { scheduleColumn.PinToLeft(_scheduleRow); } else { scheduleColumn.SetToRightOf(prevScheduleColumn, _scheduleRow); } scheduleColumn.SetWidth(COL_WIDTH); scheduleColumn.StretchHeight(_scheduleRow); _scheduleColumns[i] = scheduleColumn; prevScheduleColumn = scheduleColumn; } ViewModel.InitializeArrangers(HEIGHT_OF_HOUR, UIScheduleViewEventItemCollapsed.SPACING_WITH_NO_ADDITIONAL, UIScheduleViewEventItemCollapsed.SPACING_WITH_ADDITIONAL, UIScheduleViewEventItemCollapsed.WIDTH_OF_COLLAPSED_ITEM); ViewModel.OnFullReset += new WeakEventHandler <EventArgs>(ViewModel_OnFullReset).Handler; ViewModel.OnItemsForDateChanged += new WeakEventHandler <DateTime>(ViewModel_OnItemsForDateChanged).Handler; MainScreenViewController.ListenToTabBarHeightChanged(ref _tabBarHeightListener, delegate { // Plus 44 for the toolbar that also appears this.ContentInset = new UIEdgeInsets(0, 0, MainScreenViewController.TAB_BAR_HEIGHT + 44, 0); }); UpdateWidth(); Render(); }