public void SetViews(UIView[] views) { _stackView = new UIStackView(); _stackView.TranslatesAutoresizingMaskIntoConstraints = false; _stackView.Axis = UILayoutConstraintAxis.Vertical; _stackView.Alignment = UIStackViewAlignment.Top; _stackView.Distribution = UIStackViewDistribution.EqualSpacing; _stackView.Spacing = 0; _placeHoldersAdded = false; foreach (var view in views) { _stackView.AddArrangedSubview(view); _stackView.AddConstraint(NSLayoutConstraint.Create(view, NSLayoutAttribute.Width, NSLayoutRelation.Equal, _stackView, NSLayoutAttribute.Width, 1, 0)); } AddView(_stackView); }
public void AddPlaceHolderViewIfNeeded() { if (_scrollView.ContentSize.Height > 0 && !_placeHoldersAdded) { _placeHoldersAdded = true; var minContentHeight = _scrollViewRaisingOffset + ScrollViewHeight; nfloat bottomMargin = 0; if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0)) { bottomMargin = UIApplication.SharedApplication.KeyWindow.SafeAreaInsets.Bottom; } if (_scrollView.ContentSize.Height < minContentHeight) { var placeHolderView = new UIView(); placeHolderView.TranslatesAutoresizingMaskIntoConstraints = false; placeHolderView.AddConstraint(NSLayoutConstraint.Create(placeHolderView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1, minContentHeight - _scrollView.ContentSize.Height - bottomMargin)); _stackView.AddArrangedSubview(placeHolderView); _stackView.AddConstraint(NSLayoutConstraint.Create(placeHolderView, NSLayoutAttribute.Width, NSLayoutRelation.Equal, _stackView, NSLayoutAttribute.Width, 1, 0)); } } }
//Builds MKAnnotationView for display. MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { MKAnnotationView annotationView = null; //If the annotation is the user's location, simply return null //if (annotation is MKUserLocation) return null; //Grab pin that matches location ProctorCreekPin pin = GetPin(annotation as MKPointAnnotation); //If pin is null, we f****d up if (pin == null) { throw new Exception("Pin not found."); } annotationView = mapView.DequeueReusableAnnotation(pin.Id.ToString()); if (annotationView == null) { annotationView = new MKPinAnnotationView(annotation, pin.story.ID.ToString()); //Create container UIStackView. UIStackView containerStackView = new UIStackView(); containerStackView.Axis = UILayoutConstraintAxis.Horizontal; containerStackView.Distribution = UIStackViewDistribution.FillEqually; //Play around with this containerStackView.Alignment = UIStackViewAlignment.Fill; containerStackView.Spacing = (System.nfloat) 16.0; //Create new UIStackView for the left side, and set it up. UIStackView stackViewLeft = new UIStackView(); stackViewLeft.Axis = UILayoutConstraintAxis.Vertical; stackViewLeft.Distribution = UIStackViewDistribution.Fill; stackViewLeft.Alignment = UIStackViewAlignment.Center; stackViewLeft.Spacing = (System.nfloat) 16.0; //Create new UIStackView for the right side, and set it up. UIStackView stackViewRight = new UIStackView(); stackViewRight.Axis = UILayoutConstraintAxis.Vertical; stackViewRight.Distribution = UIStackViewDistribution.EqualSpacing; stackViewRight.Alignment = UIStackViewAlignment.Center; stackViewRight.Spacing = (System.nfloat) 16.0; //Create a new Label for the left side, and set the storyname. UILabel storyNameLabel = new UILabel(); storyNameLabel.Text = pin.story.Name; storyNameLabel.AdjustsFontSizeToFitWidth = true; //Create a new TextView for the right side, and set it to DescriptionShort //from the pin. Also set to not editable. UILabel shortDescText = new PCGUILabel(); shortDescText.Text = pin.story.Details; shortDescText.Lines = 12; shortDescText.UserInteractionEnabled = true; ((PCGUILabel)shortDescText).pin = pin; UITapGestureRecognizer descTextTap = new UITapGestureRecognizer(tap => this.OnShortDescClick(tap)) { NumberOfTapsRequired = 1 }; shortDescText.AddGestureRecognizer(descTextTap); //Create a new Label that says "Continue Reading..." for the right side. UILabel continueReadingLabel = new UILabel(); continueReadingLabel.Text = "Continue Reading"; //Create a new image for the left side, and set it from Story.PictureURL NSData imageData = null; imageData = NSData.FromUrl(new NSUrl(pin.ImageURL)); UIImage image = null; //Check if imageData is null. If it's not, then make an image if (imageData != null) { image = new UIImage(imageData); System.Diagnostics.Debug.WriteLine(image.Size); } //Add the label (for the left side) to stackViewLeft. stackViewLeft.AddArrangedSubview(storyNameLabel); //If the image isn't null, then add a UIImageView to stackView. if (image != null) { UIImageView imageView = new ScaledImageView(image); imageView.ContentMode = UIViewContentMode.ScaleAspectFit; stackViewLeft.AddArrangedSubview(imageView); stackViewLeft.AddConstraint(NSLayoutConstraint.Create(imageView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1.0f, 200)); } //Add the labels (for the right side) to stackViewRight. stackViewRight.AddArrangedSubview(shortDescText); //stackViewRight.AddConstraint(topR); //stackViewRight.AddConstraint(sidesR); /*var margins = stackViewRight.LayoutMarginsGuide; * shortDescText.LeadingAnchor.Constraint(equalTo: margins.LeadingAnchor, constant: 20).isActive = true;*/ //stackViewRight.AddArrangedSubview(continueReadingLabel); //Add the left and right StackViews to the container StackView. containerStackView.AddArrangedSubview(stackViewLeft); containerStackView.AddArrangedSubview(stackViewRight); /*var width = NSLayoutConstraint.Create(containerStackView, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1.0f, 1.0f); * var height = NSLayoutConstraint.Create(containerStackView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1.0f, 1.0f); * containerStackView.AddConstraint(width); * containerStackView.AddConstraint(height);*/ annotationView.DetailCalloutAccessoryView = containerStackView; } annotationView.CanShowCallout = true; return(annotationView); }
//Builds MKAnnotationView for display. MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { MKAnnotationView annotationView = null; //If the annotation is the user's location, simply return null //if (annotation is MKUserLocation) return null; //Grab pin that matches location ProctorCreekPin pin = GetPin(annotation as MKPointAnnotation); //If pin is null, we f****d up if (pin == null) { throw new Exception("Pin not found."); } annotationView = mapView.DequeueReusableAnnotation(pin.Id.ToString()); if (annotationView == null) { annotationView = new MKPinAnnotationView(annotation, pin.story.StoryID.ToString()); annotationView.CalloutOffset = new CGPoint(0, 0); //Create container UIStackView. UIStackView containerStackView = new UIStackView(); containerStackView.Axis = UILayoutConstraintAxis.Horizontal; containerStackView.Distribution = UIStackViewDistribution.FillEqually; //Play around with this containerStackView.Alignment = UIStackViewAlignment.Center; containerStackView.Spacing = (System.nfloat) 16.0; //Create new UIStackView for the left side, and set it up. UIStackView stackViewLeft = new UIStackView(); stackViewLeft.Axis = UILayoutConstraintAxis.Vertical; stackViewLeft.Distribution = UIStackViewDistribution.EqualSpacing; stackViewLeft.Alignment = UIStackViewAlignment.Center; stackViewLeft.Spacing = (System.nfloat) 16.0; System.Diagnostics.Debug.WriteLine("Created 1st StackView"); //Create new UIStackView for the right side, and set it up. UIStackView stackViewRight = new UIStackView(); stackViewRight.Axis = UILayoutConstraintAxis.Vertical; stackViewRight.Distribution = UIStackViewDistribution.EqualSpacing; stackViewRight.Alignment = UIStackViewAlignment.Center; stackViewRight.Spacing = (System.nfloat) 16.0; System.Diagnostics.Debug.WriteLine("Created 2nd StackView"); //Create a new Label for the left side, and set the storyname. UILabel storyNameLabel = new UILabel(); storyNameLabel.Text = pin.story.StoryName; System.Diagnostics.Debug.WriteLine("Created StoryNameLabel"); //Create a new TextView for the right side, and set it to DescriptionShort //from the pin. Also set to not editable. UILabel shortDescText = new UILabel(); shortDescText.Text = pin.story.DescriptionLong; shortDescText.Lines = 10; //shortDescText.Editable = false; System.Diagnostics.Debug.WriteLine(shortDescText.Text); //Create a new Label that says "Continue Reading..." for the right side. UILabel continueReadingLabel = new UILabel(); continueReadingLabel.Text = "Continue Reading"; System.Diagnostics.Debug.WriteLine("Created ContinueReadingLabel"); //Create a new image for the left side, and set it from Story.PictureURL NSData imageData = NSData.FromUrl(new NSUrl(pin.story.PictureURL)); UIImage image = null; //Check if imageData is null. If it's not, then make an image if (imageData != null) { image = new UIImage(imageData); } //Add the label (for the left side) to stackViewLeft. stackViewLeft.AddArrangedSubview(storyNameLabel); //If the image isn't null, then add a UIImageView to stackView. if (image != null) { UIImageView imageView = new UIImageView(image); imageView.ContentMode = UIViewContentMode.ScaleAspectFit; stackViewLeft.AddArrangedSubview(imageView); NSLayoutConstraint topL = NSLayoutConstraint.Create(imageView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, storyNameLabel, NSLayoutAttribute.Bottom, 1.0f, 2.0f); NSLayoutConstraint sidesL = NSLayoutConstraint.Create(imageView, NSLayoutAttribute.Width, NSLayoutRelation.Equal, stackViewLeft, NSLayoutAttribute.Width, 1.0f, 0.0f); stackViewLeft.AddConstraint(topL); stackViewLeft.AddConstraint(sidesL); } //annotationView.Image = null; //Add the labels (for the right side) to stackViewRight. stackViewRight.AddArrangedSubview(shortDescText); NSLayoutConstraint topR = NSLayoutConstraint.Create(shortDescText, NSLayoutAttribute.Top, NSLayoutRelation.Equal, stackViewRight, NSLayoutAttribute.Top, 1.0f, 2.0f); NSLayoutConstraint sidesR = NSLayoutConstraint.Create(shortDescText, NSLayoutAttribute.Width, NSLayoutRelation.Equal, stackViewRight, NSLayoutAttribute.Width, 1.0f, 0.0f); stackViewRight.AddConstraint(topR); stackViewRight.AddConstraint(sidesR); /*var margins = stackViewRight.LayoutMarginsGuide; * shortDescText.LeadingAnchor.Constraint(equalTo: margins.LeadingAnchor, constant: 20).isActive = true;*/ stackViewRight.AddArrangedSubview(continueReadingLabel); //Add the left and right StackViews to the container StackView. containerStackView.AddArrangedSubview(stackViewLeft); containerStackView.AddArrangedSubview(stackViewRight); //Assign stackViewLeft to the LeftCalloutAccessory of the annotation. annotationView.DetailCalloutAccessoryView = containerStackView; //annotationView.LeftCalloutAccessoryView = new UIImageView(image); //annotationView.RightCalloutAccessoryView = shortDescLabel; //Assign stackViewRight to the RightCalloutAccessory of the annotation. //annotationView.RightCalloutAccessoryView = stackViewRight; } System.Diagnostics.Debug.WriteLine(annotationView.LeftCalloutAccessoryView); annotationView.CanShowCallout = true; return(annotationView); }