{"id":89,"date":"2017-02-04T21:28:00","date_gmt":"2017-02-04T21:28:00","guid":{"rendered":"https:\/\/seimith.io\/?p=89"},"modified":"2024-07-20T00:27:24","modified_gmt":"2024-07-20T00:27:24","slug":"swift-layout-constraints","status":"publish","type":"post","link":"https:\/\/seimith.io\/pt\/2017\/02\/04\/swift-layout-constraints\/","title":{"rendered":"(Swift) Layout Constraints"},"content":{"rendered":"<p>A whiles back ago I was trying to learn how&nbsp;<code>constraints<\/code>&nbsp;work. Today, I still have no idea what the heck is going on.<\/p>\n\n\n\n<p>While learning, I can across a bunch of tutorials that helped. However, I don\u2019t remember what blog I particularly liked.<\/p>\n\n\n\n<p>This post contains a couple of classes that I made to help me add constraints to&nbsp;<code>UIViews<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/seimith\/seimith.github.io\/master\/_assets\/2017-02-19-assets\/hero.gif\" alt=\"Visual debug view of layout constraints and stacking constraints\" style=\"width:384px;height:auto\" title=\"Visual debug view of layout constraints and stacking constraints\"\/><\/figure>\n\n\n\n<p><strong>Tools:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Swift 3.0<\/li>\n\n\n\n<li>Xcode Version 8.0<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Layouting<\/h2>\n\n\n\n<p>Below is a class named&nbsp;<code>Layout<\/code>&nbsp;with a static function&nbsp;<code>setupConstraint<\/code>&nbsp;that accepts the following parameters that lets me layer&nbsp;<code>UIViews<\/code>&nbsp;that have either fixed or flexible widths and heights<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>forView: UIView\u00a0<code>\/\/ What UIView do you want to add constraints to?<\/code><\/li>\n\n\n\n<li>top: Int? = nil\u00a0<code>\/\/ Top padding<\/code><\/li>\n\n\n\n<li>bottom: Int? = nil\u00a0<code>\/\/ Bottom padding; Negative integer<\/code><\/li>\n\n\n\n<li>left: Int? = nil\u00a0<code>\/\/ Left padding<\/code><\/li>\n\n\n\n<li>right: Int? = nil\u00a0<code>\/\/ Right padding; Negative integer<\/code><\/li>\n\n\n\n<li>height: Int? = nil\u00a0<code>Specified height<\/code><\/li>\n\n\n\n<li>fixedHeight: Bool = false\u00a0<code>\/\/ Boolean defaulted to false; If you want a fixed UIView, give it a height (above)<\/code><\/li>\n\n\n\n<li>width: Int? = nil\u00a0<code>\/\/ Specified width<\/code><\/li>\n\n\n\n<li>fixedWidth: Bool = false\u00a0<code>\/\/ Boolean defaulted to false; If you want a fixed UIView, give it a width (above)<\/code><\/li>\n\n\n\n<li>selfView: UIViewController\u00a0<code>\/\/ What is the UIViewController's view?<\/code><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>import UIKit\n\nclass Layout {\n  static func setupConstraint (forView: UIView, top: Int?=nil, bottom: Int?=nil, left: Int?=nil, right: Int?=nil, height: Int?=nil, fixedHeight: Bool = false, width: Int?=nil, fixedWidth: Bool = false, selfView: UIViewController) {\n\n    var parentViewController: UIView? {\n        return selfView.view\n    }\n\n    forView.translatesAutoresizingMaskIntoConstraints = false \/\/USING AUTOLAYOUT NOT FRAMES\n\n    var l = NSLayoutConstraint() \/\/ LEFT\n    var r = NSLayoutConstraint() \/\/ RIGHT\n    var t = NSLayoutConstraint() \/\/ TOP\n    var b = NSLayoutConstraint() \/\/ BOTTOM\n\n    if (left != nil) {\n        l = forView.leadingAnchor.constraint(equalTo: (parentViewController?.leadingAnchor)!, constant: CGFloat(left!)) \/\/ LEFT\n    }\n\n    if (right != nil) {\n        r = forView.trailingAnchor.constraint(equalTo: (parentViewController?.trailingAnchor)!, constant: CGFloat(right!)) \/\/ RIGHT\n    }\n\n    if (top != nil) {\n        t = forView.topAnchor.constraint(equalTo: (parentViewController?.topAnchor)!, constant: CGFloat(top!)) \/\/ TOP\n    }\n\n    if (bottom != nil) {\n        b = forView.bottomAnchor.constraint(equalTo: (parentViewController?.bottomAnchor)!, constant: CGFloat(bottom!)) \/\/ BOTTOM\n    }\n\n    if (fixedHeight) {\n        \/\/ FIXED HEIGHT\n        let h = forView.heightAnchor.constraint(equalToConstant: CGFloat(height!))\n        parentViewController?.addConstraints(&#91;t, b, l, r, h])\n    } else if (fixedWidth) {\n        \/\/ FIXED WIDTH\n        let w = forView.widthAnchor.constraint(equalToConstant: CGFloat(width!))\n        parentViewController?.addConstraints(&#91;t, b, l, r, w])\n    } else if (fixedHeight == false &amp;&amp; fixedWidth == false) {\n        \/\/ VARIABLE HEIGHT &amp; WIDTH\n        parentViewController?.addConstraints(&#91;t, b, l, r])\n    }\n  }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Flexible Height and Width With Constraints on Top, Right, Bottom, and Left<\/h2>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/seimith\/seimith.github.io\/master\/_assets\/2017-02-19-assets\/img1.gif\" alt=\"A Cyan UIView that retains its shape in portrait and landscape mode\" style=\"width:646px;height:auto\" title=\"A Cyan UIView that retains its shape in portrait and landscape mode\"\/><\/figure>\n\n\n\n<p>This is an example of a&nbsp;<code>UIView<\/code>&nbsp;with constraints on the&nbsp;<code>top<\/code>,&nbsp;<code>right<\/code>,&nbsp;<code>bottom<\/code>, and&nbsp;<code>left<\/code>&nbsp;side. When you rotate your simulator, the shape of the&nbsp;<code>UIView<\/code>&nbsp;is flexible and the constraints, or fake margin, remain constant.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let myCyanUIView = UIView()\nmyCyanUIView.backgroundColor = UIColor.cyan\nself.view.addSubview(myCyanUIView)\n\/\/ Add layout constraint after adding my subview\nLayout.setupConstraint(forView: myCyanUIView,\n  top: 50,\n  bottom: -50,\n  left: 50,\n  right: -50,\n  \/\/height: 0, \/\/ I don't want a fixed height, so I can give this an arbitrary number or remove this paramater\n  fixedHeight: false, \/\/ &lt;===\n  \/\/width: 0, \/\/ I don't want a fixed width, so I can give this an arbitrary number or remove this paramater\n  fixedWidth: false, \/\/ &lt;===\n  selfView: self)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Fixed Width With Constraints on Top, Bottom, and Left<\/h2>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/seimith\/seimith.github.io\/master\/_assets\/2017-02-19-assets\/img2.gif\" alt=\"A red UIView that retains its shape in portrait and landscape mode\" style=\"width:650px;height:auto\" title=\"A red UIView that retains its shape in portrait and landscape mode\"\/><\/figure>\n\n\n\n<p>This example is of a&nbsp;<code>UIView<\/code>&nbsp;\u201cpegged\u201d to the left side of the viewport. The height will vary upon the orientation of the device.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let myRedUIView = UIView()\nmyRedUIView.backgroundColor = UIColor.red\nself.view.addSubview(myRedUIView)\n\/\/ Add layout constraint after adding my subview\nLayout.setupConstraint(forView: myRedUIView,\n  top: 75,\n  bottom: -75,\n  left: 75,\n  right: nil, \/\/ &lt;=== I want my UIView to be fixed on the left side\n  \/\/height: 0,\n  fixedHeight: false, \/\/ &lt;=== With no fixed height\n  width: 100, \/\/ &lt;=== With a fixed width\n  fixedWidth: true, \/\/ &lt;=== So, I set this to true\n  selfView: self)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Fixed Height With Constraints on Right, Bottom, and Left<\/h2>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/seimith\/seimith.github.io\/master\/_assets\/2017-02-19-assets\/img3.gif\" alt=\"A green UIView that retains its shape in portrait and landscape mode\" style=\"width:648px;height:auto\" title=\"A green UIView that retains its shape in portrait and landscape mode\"\/><\/figure>\n\n\n\n<p>This example is of a&nbsp;<code>UIView<\/code>&nbsp;\u201cpegged\u201d to the bottom side of the viewport. The height is fixed and the width will vary upon the orientation of the device.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let myGreenUIView = UIView()\nmyGreenUIView.backgroundColor = UIColor.green\nself.view.addSubview(myGreenUIView)\n\/\/ Add layout constraint after adding my subview\nLayout.setupConstraint(forView: myGreenUIView,\n  top: nil, \/\/ &lt;===\n  bottom: -100,\n  left: 100,\n  right: -100,\n  height: 100, \/\/ &lt;===\n  fixedHeight: true,\n  \/\/width: 100, \/\/ &lt;=== I want flexible width\n  fixedWidth: false, \/\/ &lt;=== I want flexible width\n  selfView: self)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Stacking<\/h2>\n\n\n\n<p>This class,&nbsp;<code>Stack<\/code>, lets me stack&nbsp;<code>UIViews<\/code>. The private function accepts the following parameters:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>views:\u00a0<code>[UIView]<\/code>\u00a0\/\/ Array of\u00a0<code>UIViews<\/code><\/li>\n\n\n\n<li>axis:\u00a0<code>UILayoutConstraintAxis<\/code><\/li>\n\n\n\n<li>distribution:\u00a0<code>UIStackViewDistribution<\/code><\/li>\n\n\n\n<li>alignment:\u00a0<code>UIStackViewAlignment<\/code><\/li>\n\n\n\n<li>spacing:\u00a0<code>Int? = 0<\/code>,<\/li>\n\n\n\n<li>selfView:\u00a0<code>UIViewController<\/code>,<\/li>\n\n\n\n<li>parentContainer:\u00a0<code>UIView? = nil<\/code><\/li>\n<\/ul>\n\n\n\n<p>I can use this in conjunction with the&nbsp;<code>Layout<\/code>&nbsp;class above.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import UIKit\n\nclass Stack {\n    static func setupConstraints (views: &#91;UIView], axis: UILayoutConstraintAxis, distribution: UIStackViewDistribution, alignment: UIStackViewAlignment, spacing: Int?=0, selfView: UIViewController, parentContainer: UIView?=nil) {\n\n        var parentViewController: UIView! {\n            return selfView.view\n        }\n\n        var pContainer = UIView()\n        if (parentContainer != nil) {\n            pContainer = parentContainer!\n        } else {\n            pContainer = parentViewController\n        }\n\n        let stackView = UIStackView()\n        stackView.axis = axis\n        stackView.distribution = distribution\n        stackView.alignment = alignment\n        stackView.spacing = CGFloat(spacing!)\n\n        for view in views {\n            var height = Int()\n            var width = Int()\n\n            if (view.frame.size.height != 0.0 &amp;&amp; view.frame.size.width != 0.0) {\n                height = Int(view.frame.size.height)\n                width = Int(view.frame.size.width)\n            } else {\n                height = 100\n                width = 100\n            }\n            stackView.addArrangedSubview(view)\n            view.heightAnchor.constraint(equalToConstant: CGFloat(height)).isActive = true\n            view.widthAnchor.constraint(equalToConstant: CGFloat(width)).isActive = true\n        }\n\n        stackView.translatesAutoresizingMaskIntoConstraints = false;\n        parentViewController.addSubview(stackView)\n\n        \/\/ Constraints FOR NESTING LOCATION\n        let l = stackView.leadingAnchor.constraint(equalTo: pContainer.leadingAnchor)\n        let t = stackView.topAnchor.constraint(equalTo: pContainer.topAnchor)\n        parentViewController.addConstraints(&#91;l, t])\n    }\n}<\/code><\/pre>\n\n\n\n<p>Once you add this&nbsp;<code>stacking<\/code>&nbsp;class to your project, you can consume it like so:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let myYellowUIView = UIView()\nmyYellowUIView.backgroundColor = UIColor.yellow\n\nlet myOrangeUIView = UIView()\nmyOrangeUIView.backgroundColor = UIColor.orange\n\nlet myBlueUIView = UIView()\nmyBlueUIView.backgroundColor = UIColor.blue\n\nStack.setupConstraints(views: &#91;myYellowUIView, myOrangeUIView, myBlueUIView],\n  axis: .horizontal,\n  distribution: .fill,\n  alignment: .leading,\n  spacing: 20,\n  selfView: self,\n  parentContainer: myYellowUIView)\n\nLayout.setupConstraint(forView: myYellowUIView,\n  top: 50,\n  \/\/bottom: nil,\n  left: 20,\n  \/\/right: nil,\n  height: 100,\n  fixedHeight: true,\n  width: 100,\n  fixedWidth: true,\n  selfView: self)<\/code><\/pre>\n\n\n\n<p>Unfortunately, I\u2019m personally not very excited about the stacking because I didn\u2019t flesh it out yet.<\/p>\n\n\n\n<p>All it appears to be doing is what you can do when setting the&nbsp;<code>frame's<\/code>&nbsp;<code>CGRect<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img decoding=\"async\" src=\"https:\/\/determined-mcnulty-44b4a3.netlify.app\/static\/bbcc9ab0d408e857173faa471b0988db\/f058b\/img4.png\" alt=\"&quot;Three UIViews that are stacked horizontally&quot;\" style=\"width:339px;height:auto\" title=\"Three UIViews that are stacked horizontally\"\/><\/figure>\n\n\n\n<p><a href=\"https:\/\/determined-mcnulty-44b4a3.netlify.app\/static\/bbcc9ab0d408e857173faa471b0988db\/09e48\/img4.png\" target=\"_blank\" rel=\"noreferrer noopener\"><\/a><\/p>\n\n\n\n<p><strong>You can get the storyboard project is in&nbsp;<a href=\"https:\/\/github.com\/seimith\/SwiftAddConstraints\">this repo<\/a>.<\/strong><\/p>","protected":false},"excerpt":{"rendered":"<p>A whiles back ago I was trying to learn how&nbsp;constraints&nbsp;work. Today, I still have no idea what the heck is going on. While learning, I can across a bunch of tutorials that helped. However, I don\u2019t remember what blog I particularly liked. This post contains a couple of classes that I made to help me [&hellip;]<\/p>","protected":false},"author":1,"featured_media":289,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[20],"class_list":["post-89","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-post","tag-code"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>(Swift) Layout Constraints - S(ei)mith.io<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/seimith.io\/pt\/2017\/02\/04\/swift-layout-constraints\/\" \/>\n<meta property=\"og:locale\" content=\"pt_BR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"(Swift) Layout Constraints - S(ei)mith.io\" \/>\n<meta property=\"og:description\" content=\"A whiles back ago I was trying to learn how&nbsp;constraints&nbsp;work. Today, I still have no idea what the heck is going on. While learning, I can across a bunch of tutorials that helped. However, I don\u2019t remember what blog I particularly liked. This post contains a couple of classes that I made to help me [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/seimith.io\/pt\/2017\/02\/04\/swift-layout-constraints\/\" \/>\n<meta property=\"og:site_name\" content=\"S(ei)mith.io\" \/>\n<meta property=\"article:published_time\" content=\"2017-02-04T21:28:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-07-20T00:27:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/seimith.io\/wp-content\/uploads\/2017\/02\/hero.gif\" \/>\n\t<meta property=\"og:image:width\" content=\"480\" \/>\n\t<meta property=\"og:image:height\" content=\"759\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/gif\" \/>\n<meta name=\"author\" content=\"Smith\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Smith\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/seimith.io\\\/2017\\\/02\\\/04\\\/swift-layout-constraints\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/seimith.io\\\/2017\\\/02\\\/04\\\/swift-layout-constraints\\\/\"},\"author\":{\"name\":\"Smith\",\"@id\":\"https:\\\/\\\/seimith.io\\\/#\\\/schema\\\/person\\\/315065130ef0017986daf9a1127ce80a\"},\"headline\":\"(Swift) Layout Constraints\",\"datePublished\":\"2017-02-04T21:28:00+00:00\",\"dateModified\":\"2024-07-20T00:27:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/seimith.io\\\/2017\\\/02\\\/04\\\/swift-layout-constraints\\\/\"},\"wordCount\":354,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/seimith.io\\\/2017\\\/02\\\/04\\\/swift-layout-constraints\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/seimith.io\\\/wp-content\\\/uploads\\\/2017\\\/02\\\/hero.gif\",\"keywords\":[\"Code\"],\"articleSection\":[\"Post\"],\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/seimith.io\\\/2017\\\/02\\\/04\\\/swift-layout-constraints\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/seimith.io\\\/2017\\\/02\\\/04\\\/swift-layout-constraints\\\/\",\"url\":\"https:\\\/\\\/seimith.io\\\/2017\\\/02\\\/04\\\/swift-layout-constraints\\\/\",\"name\":\"(Swift) Layout Constraints - S(ei)mith.io\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/seimith.io\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/seimith.io\\\/2017\\\/02\\\/04\\\/swift-layout-constraints\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/seimith.io\\\/2017\\\/02\\\/04\\\/swift-layout-constraints\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/seimith.io\\\/wp-content\\\/uploads\\\/2017\\\/02\\\/hero.gif\",\"datePublished\":\"2017-02-04T21:28:00+00:00\",\"dateModified\":\"2024-07-20T00:27:24+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/seimith.io\\\/#\\\/schema\\\/person\\\/315065130ef0017986daf9a1127ce80a\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/seimith.io\\\/2017\\\/02\\\/04\\\/swift-layout-constraints\\\/#breadcrumb\"},\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/seimith.io\\\/2017\\\/02\\\/04\\\/swift-layout-constraints\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\\\/\\\/seimith.io\\\/2017\\\/02\\\/04\\\/swift-layout-constraints\\\/#primaryimage\",\"url\":\"https:\\\/\\\/seimith.io\\\/wp-content\\\/uploads\\\/2017\\\/02\\\/hero.gif\",\"contentUrl\":\"https:\\\/\\\/seimith.io\\\/wp-content\\\/uploads\\\/2017\\\/02\\\/hero.gif\",\"width\":480,\"height\":759},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/seimith.io\\\/2017\\\/02\\\/04\\\/swift-layout-constraints\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/seimith.io\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"(Swift) Layout Constraints\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/seimith.io\\\/#website\",\"url\":\"https:\\\/\\\/seimith.io\\\/\",\"name\":\"s(ei)mith.io\",\"description\":\"Ramblings written by\u00a0Smith Suth\u00a0who works at the intersection of Engineering, Product, and Design.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/seimith.io\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"pt-BR\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/seimith.io\\\/#\\\/schema\\\/person\\\/315065130ef0017986daf9a1127ce80a\",\"name\":\"Smith\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a403a51628e8e4553b69960e9eb8b67184121e56ddf2fdf28c5f9515bb518208?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a403a51628e8e4553b69960e9eb8b67184121e56ddf2fdf28c5f9515bb518208?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a403a51628e8e4553b69960e9eb8b67184121e56ddf2fdf28c5f9515bb518208?s=96&d=mm&r=g\",\"caption\":\"Smith\"},\"sameAs\":[\"https:\\\/\\\/seimith.io\"],\"url\":\"https:\\\/\\\/seimith.io\\\/pt\\\/author\\\/seimithsuth\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"(Swift) Layout Constraints - S(ei)mith.io","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/seimith.io\/pt\/2017\/02\/04\/swift-layout-constraints\/","og_locale":"pt_BR","og_type":"article","og_title":"(Swift) Layout Constraints - S(ei)mith.io","og_description":"A whiles back ago I was trying to learn how&nbsp;constraints&nbsp;work. Today, I still have no idea what the heck is going on. While learning, I can across a bunch of tutorials that helped. However, I don\u2019t remember what blog I particularly liked. This post contains a couple of classes that I made to help me [&hellip;]","og_url":"https:\/\/seimith.io\/pt\/2017\/02\/04\/swift-layout-constraints\/","og_site_name":"S(ei)mith.io","article_published_time":"2017-02-04T21:28:00+00:00","article_modified_time":"2024-07-20T00:27:24+00:00","og_image":[{"width":480,"height":759,"url":"https:\/\/seimith.io\/wp-content\/uploads\/2017\/02\/hero.gif","type":"image\/gif"}],"author":"Smith","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smith","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/seimith.io\/2017\/02\/04\/swift-layout-constraints\/#article","isPartOf":{"@id":"https:\/\/seimith.io\/2017\/02\/04\/swift-layout-constraints\/"},"author":{"name":"Smith","@id":"https:\/\/seimith.io\/#\/schema\/person\/315065130ef0017986daf9a1127ce80a"},"headline":"(Swift) Layout Constraints","datePublished":"2017-02-04T21:28:00+00:00","dateModified":"2024-07-20T00:27:24+00:00","mainEntityOfPage":{"@id":"https:\/\/seimith.io\/2017\/02\/04\/swift-layout-constraints\/"},"wordCount":354,"commentCount":0,"image":{"@id":"https:\/\/seimith.io\/2017\/02\/04\/swift-layout-constraints\/#primaryimage"},"thumbnailUrl":"https:\/\/seimith.io\/wp-content\/uploads\/2017\/02\/hero.gif","keywords":["Code"],"articleSection":["Post"],"inLanguage":"pt-BR","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/seimith.io\/2017\/02\/04\/swift-layout-constraints\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/seimith.io\/2017\/02\/04\/swift-layout-constraints\/","url":"https:\/\/seimith.io\/2017\/02\/04\/swift-layout-constraints\/","name":"(Swift) Layout Constraints - S(ei)mith.io","isPartOf":{"@id":"https:\/\/seimith.io\/#website"},"primaryImageOfPage":{"@id":"https:\/\/seimith.io\/2017\/02\/04\/swift-layout-constraints\/#primaryimage"},"image":{"@id":"https:\/\/seimith.io\/2017\/02\/04\/swift-layout-constraints\/#primaryimage"},"thumbnailUrl":"https:\/\/seimith.io\/wp-content\/uploads\/2017\/02\/hero.gif","datePublished":"2017-02-04T21:28:00+00:00","dateModified":"2024-07-20T00:27:24+00:00","author":{"@id":"https:\/\/seimith.io\/#\/schema\/person\/315065130ef0017986daf9a1127ce80a"},"breadcrumb":{"@id":"https:\/\/seimith.io\/2017\/02\/04\/swift-layout-constraints\/#breadcrumb"},"inLanguage":"pt-BR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/seimith.io\/2017\/02\/04\/swift-layout-constraints\/"]}]},{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/seimith.io\/2017\/02\/04\/swift-layout-constraints\/#primaryimage","url":"https:\/\/seimith.io\/wp-content\/uploads\/2017\/02\/hero.gif","contentUrl":"https:\/\/seimith.io\/wp-content\/uploads\/2017\/02\/hero.gif","width":480,"height":759},{"@type":"BreadcrumbList","@id":"https:\/\/seimith.io\/2017\/02\/04\/swift-layout-constraints\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/seimith.io\/"},{"@type":"ListItem","position":2,"name":"(Swift) Layout Constraints"}]},{"@type":"WebSite","@id":"https:\/\/seimith.io\/#website","url":"https:\/\/seimith.io\/","name":"s(ei)mith.io","description":"Ramblings written by\u00a0Smith Suth\u00a0who works at the intersection of Engineering, Product, and Design.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/seimith.io\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"pt-BR"},{"@type":"Person","@id":"https:\/\/seimith.io\/#\/schema\/person\/315065130ef0017986daf9a1127ce80a","name":"Smith","image":{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/secure.gravatar.com\/avatar\/a403a51628e8e4553b69960e9eb8b67184121e56ddf2fdf28c5f9515bb518208?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/a403a51628e8e4553b69960e9eb8b67184121e56ddf2fdf28c5f9515bb518208?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a403a51628e8e4553b69960e9eb8b67184121e56ddf2fdf28c5f9515bb518208?s=96&d=mm&r=g","caption":"Smith"},"sameAs":["https:\/\/seimith.io"],"url":"https:\/\/seimith.io\/pt\/author\/seimithsuth\/"}]}},"_links":{"self":[{"href":"https:\/\/seimith.io\/pt\/wp-json\/wp\/v2\/posts\/89","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/seimith.io\/pt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seimith.io\/pt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seimith.io\/pt\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/seimith.io\/pt\/wp-json\/wp\/v2\/comments?post=89"}],"version-history":[{"count":1,"href":"https:\/\/seimith.io\/pt\/wp-json\/wp\/v2\/posts\/89\/revisions"}],"predecessor-version":[{"id":90,"href":"https:\/\/seimith.io\/pt\/wp-json\/wp\/v2\/posts\/89\/revisions\/90"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/seimith.io\/pt\/wp-json\/wp\/v2\/media\/289"}],"wp:attachment":[{"href":"https:\/\/seimith.io\/pt\/wp-json\/wp\/v2\/media?parent=89"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seimith.io\/pt\/wp-json\/wp\/v2\/categories?post=89"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seimith.io\/pt\/wp-json\/wp\/v2\/tags?post=89"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}