# Autoresizing Masks and You

DevFeed: [Autoresizing Masks and You](<https://devfeed.tech/articles/autoresizing-masks-and-you-22313.md>)

Original publisher: [Read original article](<https://www.thecodedself.com/autoresizing-masks/>)

Author: Keegan Rush

Published: 2018-01-23T00:00:00Z

Content type: tutorial

Language: en

Sources: [The Coded Self](<https://devfeed.tech/sources/the-coded-self.md>)

Topics: [iOS](<https://devfeed.tech/topics/ios.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [console](<https://devfeed.tech/tags/console.md>), [container](<https://devfeed.tech/tags/container.md>), [interface](<https://devfeed.tech/tags/interface.md>), [layout](<https://devfeed.tech/tags/layout.md>), [property](<https://devfeed.tech/tags/property.md>), [spring](<https://devfeed.tech/tags/spring.md>)

## AI overview

This tutorial explains how autoresizing masks work in iOS and why they can conflict with Auto Layout constraints. It describes the springs-and-struts layout model, the mask values that control resizing and positioning, and how UIKit converts autoresizing behavior into automatic constraints.

## Source excerpt

You're an Autolayout Wizard. You know Interface Builder like the back of your hand. Then, one day, you create a simple UIView, add it as a subview with some elegantly crafted constraints, and.. it blows up in your face. What gives? Take a look at this code example that tries to create a UILabel and center it in the view. let centerLabel = UILabel() centerLabel.text = "Perfectly centered!" view.addSubview(centerLabel) NSLayoutConstraint.activate([ centerLabel.centerXAnchor.constraint( equalTo: view.centerXAnchor, constant: 0), centerLabel.centerYAnchor.constraint( equalTo: view.centerYAnchor, constant: 0) ]) Try this, and you'll be thoroughly disappointed. The perfectly centered label is nowhere to be found. Luckily, the console output provides a vital clue. [LayoutConstraints] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) ( "<NSAutoresizingMaskLayoutConstraint:0x60400009cb60 h=--& v=--& UILabel:0x7f927f2021b0'Perfectly centered!'.midY == 0 (active)>", "<NSLayoutConstraint:0x608000099140 UILabel:0x7f927f2021b0'Perfectly centered!'.centerY == UIView:0x7f927f1017b0.centerY (active)>", "<NSLayoutConstraint:0x60400009cd90 'UIView-Encapsulated-Layout-Height' UIView:0x7f927f1017b0.height == 568 (active)>", "<NSAutoresizingMaskLayoutConstraint:0x60400009ce30 h=-&- v=-&- 'UIView-Encapsulated-Layout-Top' UIView:0x7f927f1017b0.minY == 0 (active, names: '|':UIWindow:0x7f927bd073a0 )>" ) Will attempt to recover by breaking constraint <NSLayoutConstraint:0x608000099140 UILabel:0x7f927f2021b0'Perfectly centered!'.centerY == UIView:0x7f927f1017b0.centerY (act