Пример #1
0
        /// <summary>
        /// Creates the initial layout for the app
        /// </summary>
        private void CreateLayout()
        {
            // Set the text on the two buttons
            _mySearchButton.SetTitle("Search All", UIControlState.Normal);
            _mySearchRestrictedButton.SetTitle("Search in View", UIControlState.Normal);

            // Set the default location and search text
            _myLocationBox.Text = "Current Location";
            _mySearchBox.Text   = "Coffee";

            // Allow pressing 'return' to dismiss the keyboard
            _myLocationBox.ShouldReturn += (textField) => { textField.ResignFirstResponder(); return(true); };
            _mySearchBox.ShouldReturn   += (textField) => { textField.ResignFirstResponder(); return(true); };

            // Gray out the buttons when they are disabled
            _mySearchButton.SetTitleColor(UIColor.Gray, UIControlState.Disabled);
            _mySearchRestrictedButton.SetTitleColor(UIColor.Gray, UIControlState.Disabled);

            // Change button color when enabled
            _mySearchButton.SetTitleColor(UIColor.Blue, UIControlState.Normal);
            _mySearchRestrictedButton.SetTitleColor(UIColor.Blue, UIControlState.Normal);

            // Color the textboxes and buttons to appear over the mapview
            UIColor background = UIColor.FromWhiteAlpha(.85f, .95f);

            _mySearchBox.BackgroundColor              = background;
            _myLocationBox.BackgroundColor            = background;
            _mySearchButton.BackgroundColor           = background;
            _mySearchRestrictedButton.BackgroundColor = background;
            _myProgressBar.BackgroundColor            = background;

            // Hide the activity indicator (progress bar) when stopped
            _myProgressBar.HidesWhenStopped = true;

            // Set radii to make it look nice
            _mySearchRestrictedButton.Layer.CornerRadius = 5;
            _mySearchButton.Layer.CornerRadius           = 5;
            _myLocationBox.Layer.CornerRadius            = 5;
            _mySearchBox.Layer.CornerRadius = 5;

            // Make sure the suggestion list is hidden by default
            _mySuggestionView.Hidden = true;

            // Create the suggestion source
            _mySuggestionSource = new SuggestionSource(null, this);

            // Set the source for the table view
            _mySuggestionView.Source = _mySuggestionSource;

            // Enable tap-for-info pattern on results
            _myMapView.GeoViewTapped += _myMapView_GeoViewTapped;

            // Listen for taps on the search buttons
            _mySearchButton.TouchUpInside           += _mySearchButton_Clicked;
            _mySearchRestrictedButton.TouchUpInside += _mySearchRestrictedButton_Click;

            // Listen for text-changed events
            _mySearchBox.AllEditingEvents   += _mySearchBox_TextChanged;
            _myLocationBox.AllEditingEvents += _myLocationBox_TextChanged;

            // Add the views
            View.AddSubviews(_myMapView, _mySearchBox, _myLocationBox, _mySearchButton, _mySearchRestrictedButton, _myProgressBar, _mySuggestionView);
        }
Пример #2
0
        public override void LoadView()
        {
            // Create the views.
            View = new UIView {
                BackgroundColor = UIColor.White
            };

            _myMapView = new MapView();
            _myMapView.TranslatesAutoresizingMaskIntoConstraints = false;

            UIView formContainer = new UIView {
                BackgroundColor = UIColor.FromWhiteAlpha(1f, .8f)
            };

            formContainer.TranslatesAutoresizingMaskIntoConstraints = false;

            _searchBox = new UITextField();
            _searchBox.TranslatesAutoresizingMaskIntoConstraints = false;
            _searchBox.Text         = "Coffee";
            _searchBox.BorderStyle  = UITextBorderStyle.RoundedRect;
            _searchBox.LeftView     = new UIView(new CGRect(0, 0, 5, 20));
            _searchBox.LeftViewMode = UITextFieldViewMode.Always;

            _locationBox = new UITextField();
            _locationBox.TranslatesAutoresizingMaskIntoConstraints = false;
            _locationBox.Text         = "Current location";
            _locationBox.BorderStyle  = UITextBorderStyle.RoundedRect;
            _locationBox.LeftView     = new UIView(new CGRect(0, 0, 5, 20));
            _locationBox.LeftViewMode = UITextFieldViewMode.Always;

            _searchButton = new UIButton(UIButtonType.RoundedRect);
            _searchButton.BackgroundColor = UIColor.White;
            _searchButton.TranslatesAutoresizingMaskIntoConstraints = false;
            _searchButton.SetTitle("Search all", UIControlState.Normal);
            _searchButton.SetTitleColor(UIColor.Gray, UIControlState.Disabled);
            _searchButton.SetTitleColor(View.TintColor, UIControlState.Normal);
            _searchButton.Layer.CornerRadius = 5;
            _searchButton.Layer.BorderColor  = View.TintColor.CGColor;
            _searchButton.Layer.BorderWidth  = 1;

            _searchInViewButton = new UIButton(UIButtonType.RoundedRect);
            _searchInViewButton.BackgroundColor = UIColor.White;
            _searchInViewButton.TranslatesAutoresizingMaskIntoConstraints = false;
            _searchInViewButton.SetTitle("Search in view", UIControlState.Normal);
            _searchInViewButton.SetTitleColor(UIColor.Gray, UIControlState.Disabled);
            _searchInViewButton.SetTitleColor(View.TintColor, UIControlState.Normal);
            _searchInViewButton.Layer.CornerRadius = 5;
            _searchInViewButton.Layer.BorderColor  = View.TintColor.CGColor;
            _searchInViewButton.Layer.BorderWidth  = 1;

            _activityView = new UIActivityIndicatorView(UIActivityIndicatorViewStyle.WhiteLarge);
            _activityView.TranslatesAutoresizingMaskIntoConstraints = false;
            _activityView.HidesWhenStopped = true;
            _activityView.BackgroundColor  = UIColor.FromWhiteAlpha(0, .5f);

            _suggestionView = new UITableView();
            _suggestionView.TranslatesAutoresizingMaskIntoConstraints = false;
            _suggestionView.Hidden    = true;
            _mySuggestionSource       = new SuggestionSource(null, this);
            _suggestionView.Source    = _mySuggestionSource;
            _suggestionView.RowHeight = 24;

            // Add the views.
            View.AddSubviews(_myMapView, formContainer, _searchBox, _locationBox, _searchButton,
                             _searchInViewButton, _activityView, _suggestionView);

            // Lay out the views.
            NSLayoutConstraint.ActivateConstraints(new[]
            {
                _myMapView.TopAnchor.ConstraintEqualTo(formContainer.BottomAnchor),
                _myMapView.LeadingAnchor.ConstraintEqualTo(View.LeadingAnchor),
                _myMapView.TrailingAnchor.ConstraintEqualTo(View.TrailingAnchor),
                _myMapView.BottomAnchor.ConstraintEqualTo(View.BottomAnchor),

                _searchBox.TopAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.TopAnchor, 8),
                _searchBox.LeadingAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.LeadingAnchor, 8),
                _searchBox.TrailingAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.TrailingAnchor, -8),

                _locationBox.TopAnchor.ConstraintEqualTo(_searchBox.BottomAnchor, 8),
                _locationBox.LeadingAnchor.ConstraintEqualTo(_searchBox.LeadingAnchor),
                _locationBox.TrailingAnchor.ConstraintEqualTo(_searchBox.TrailingAnchor),

                _searchButton.TopAnchor.ConstraintEqualTo(_locationBox.BottomAnchor, 8),
                _searchButton.LeadingAnchor.ConstraintEqualTo(_searchBox.LeadingAnchor),
                _searchButton.TrailingAnchor.ConstraintEqualTo(View.CenterXAnchor, -4),
                _searchButton.HeightAnchor.ConstraintEqualTo(32),

                _searchInViewButton.TopAnchor.ConstraintEqualTo(_searchButton.TopAnchor),
                _searchInViewButton.LeadingAnchor.ConstraintEqualTo(View.CenterXAnchor, 4),
                _searchInViewButton.TrailingAnchor.ConstraintEqualTo(_searchBox.TrailingAnchor),
                _searchInViewButton.HeightAnchor.ConstraintEqualTo(32),

                formContainer.TopAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.TopAnchor),
                formContainer.LeadingAnchor.ConstraintEqualTo(View.LeadingAnchor),
                formContainer.TrailingAnchor.ConstraintEqualTo(View.TrailingAnchor),
                formContainer.BottomAnchor.ConstraintEqualTo(_searchInViewButton.BottomAnchor, 8),

                _activityView.TopAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.TopAnchor),
                _activityView.LeadingAnchor.ConstraintEqualTo(View.LeadingAnchor),
                _activityView.TrailingAnchor.ConstraintEqualTo(View.TrailingAnchor),
                _activityView.BottomAnchor.ConstraintEqualTo(View.BottomAnchor),

                _suggestionView.TopAnchor.ConstraintEqualTo(formContainer.BottomAnchor, 8),
                _suggestionView.LeadingAnchor.ConstraintEqualTo(_locationBox.LeadingAnchor, 8),
                _suggestionView.TrailingAnchor.ConstraintEqualTo(_locationBox.TrailingAnchor, -8),
                _suggestionView.HeightAnchor.ConstraintEqualTo(_suggestionView.RowHeight * 4)
            });
        }
Пример #3
0
        private void CreateLayout()
        {
            // Set the text on the two buttons.
            _searchButton.SetTitle("Search all", UIControlState.Normal);
            _searchRestrictedButton.SetTitle("Search in view", UIControlState.Normal);

            // Set the default location and search text.
            _locationBox.Text = "Current location";
            _searchBox.Text   = "Coffee";

            // Allow pressing 'return' to dismiss the keyboard.
            _locationBox.ShouldReturn += textField =>
            {
                textField.ResignFirstResponder();
                return(true);
            };
            _searchBox.ShouldReturn += textField =>
            {
                textField.ResignFirstResponder();
                return(true);
            };

            // Gray out the buttons when they are disabled.
            _searchButton.SetTitleColor(UIColor.Gray, UIControlState.Disabled);
            _searchRestrictedButton.SetTitleColor(UIColor.Gray, UIControlState.Disabled);

            // Change button color when enabled.
            _searchButton.SetTitleColor(View.TintColor, UIControlState.Normal);
            _searchRestrictedButton.SetTitleColor(View.TintColor, UIControlState.Normal);

            // Hide the activity indicator (progress bar) when stopped.
            _activityView.HidesWhenStopped           = true;
            _activityView.ActivityIndicatorViewStyle = UIActivityIndicatorViewStyle.WhiteLarge;
            _activityView.BackgroundColor            = UIColor.FromWhiteAlpha(0, .5f);

            // Make the textboxes look nice.
            _locationBox.BorderStyle = UITextBorderStyle.RoundedRect;
            _searchBox.BorderStyle   = UITextBorderStyle.RoundedRect;

            // Make the buttons look nice.
            _searchButton.Layer.CornerRadius           = 5;
            _searchRestrictedButton.Layer.CornerRadius = 5;

            // Make sure the suggestion list is hidden by default.
            _suggestionView.Hidden = true;

            // Create the suggestion source.
            _mySuggestionSource = new SuggestionSource(null, this);

            // Set the source for the table view.
            _suggestionView.Source = _mySuggestionSource;

            // Enable tap-for-info pattern on results.
            _myMapView.GeoViewTapped += MapView_GeoViewTapped;

            // Listen for taps on the search buttons.
            _searchButton.TouchUpInside           += SearchButton_Touched;
            _searchRestrictedButton.TouchUpInside += SearchRestrictedButton_Touched;

            // Listen for text-changed events.
            _searchBox.AllEditingEvents   += SearchBox_TextChanged;
            _locationBox.AllEditingEvents += LocationBox_TextChanged;

            // Set padding on the text views.
            _searchBox.LeftView       = new UIView(new CGRect(0, 0, 5, 20));
            _searchBox.LeftViewMode   = UITextFieldViewMode.Always;
            _locationBox.LeftView     = new UIView(new CGRect(0, 0, 5, 20));
            _locationBox.LeftViewMode = UITextFieldViewMode.Always;

            // Add the views.
            View.AddSubviews(_myMapView, _toolbar, _searchBox, _locationBox, _searchButton,
                             _searchRestrictedButton, _activityView, _suggestionView);
        }