Skip to content

Instantly share code, notes, and snippets.

@lobrien
Created August 21, 2019 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lobrien/e19fe05dbc932ac4879ed67d48743ce9 to your computer and use it in GitHub Desktop.
Save lobrien/e19fe05dbc932ac4879ed67d48743ce9 to your computer and use it in GitHub Desktop.
Simple layout anchor example
faceContainingImage.Image = UIImage.FromFile("docs.jpg");
//Put it on the screen
View.AddSubview(faceContainingImage);
faceContainingImage.TranslatesAutoresizingMaskIntoConstraints = false;
var dpConstraints = new[]
{
faceContainingImage.LeadingAnchor.ConstraintEqualTo(View.LayoutMarginsGuide.LeadingAnchor),
faceContainingImage.TrailingAnchor.ConstraintEqualTo(View.LayoutMarginsGuide.TrailingAnchor),
faceContainingImage.TopAnchor.ConstraintEqualTo(View.LayoutMarginsGuide.TopAnchor, 40.0f),
faceContainingImage.HeightAnchor.ConstraintEqualTo(View.LayoutMarginsGuide.HeightAnchor, (nfloat) 0.5)
};
NSLayoutConstraint.ActivateConstraints(dpConstraints);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment