Beispiel #1
0
        public void OnSuggestions(Suggestion[] suggestions)
        {
            foreach (UIView view in Subviews)
            {
                if (view is SuggestionView)
                {
                    view.RemoveFromSuperview();
                }
            }

            suggestionHeight = TraitCollection.HorizontalSizeClass == UIUserInterfaceSizeClass.Regular
                               ? suggestionHeightRegular
                               : suggestionHeightCompact;

            for (int i = 0; i < suggestions.Length; i++)
            {
                var suggestionView = SuggestionView.Create();
                suggestionView.Suggestion = suggestions[i];
                AddSubview(suggestionView);
                suggestionView.TranslatesAutoresizingMaskIntoConstraints = false;
                suggestionView.HeightAnchor.ConstraintEqualTo(suggestionHeight).Active         = true;
                suggestionView.CenterXAnchor.ConstraintEqualTo(Superview.CenterXAnchor).Active = true;
                suggestionView.WidthAnchor.ConstraintEqualTo(Superview.WidthAnchor, 1, -2 * sideMargin).Active        = true;
                suggestionView.TopAnchor.ConstraintEqualTo(titleLabel.BottomAnchor, distanceFromTitleLabel(i)).Active = true;

                suggestionView.AddGestureRecognizer(new UITapGestureRecognizer(() =>
                {
                    SuggestionTapped.OnNext(suggestionView.Suggestion);
                }));
            }
            heightConstraint.Constant = heightForSuggestionCount(suggestions.Length);
            heightConstraint.Active   = true;
            SetNeedsLayout();
        }
Beispiel #2
0
        public SuggestionsView()
        {
            TranslatesAutoresizingMaskIntoConstraints = false;
            BackgroundColor = UIColor.White;
            ClipsToBounds   = true;

            for (int i = 0; i < suggestionCount; i++)
            {
                suggestionViews.Add(SuggestionView.Create());
            }
        }