SlideShare a Scribd company logo
1 of 25
Auto Layouts
Lakhdeep Singh Jawandha
What is Auto Layout?
Auto Layout is a new way to define dynamic
GUIs. Before, we had autoresizing masks, that
described how a subview will resize or move when
its superview is resized. With Auto Layout you can
do the same and also a lot more complicated GUIs
quite easily.
• Auto Layout minimizes your calculation.
• Auto Layout design is indirect, but it’s also more flexible.
• Auto Layout is driven by geometry.
• Auto Layout focuses on relationships.
• Support different screen sizes in your apps .
• Auto Layout seeks optimal solutions.
Features
Enable it
Constraint
A Mathematical representation of a human : expressible statement
"the left edge should be 20pt of the superviews left
edge"
view.left = (superview.left + 20)
y = m * x+ c
(y = attribute1 = view.left)
(x = attribute2 = superview.left)
(m = multiplier = 1)
(c = constant = 20)
Constraint
‣ Two items with an attribute
‣ Constant
‣ Relation
‣ Multiplier
‣ Priority level
Attribute?
‣ Left
‣ Right
‣ Top
‣ Bottom
‣ Leading ~ left or right depending on language settings
‣ Trailing ~ right or left depending on language settings ‣ width
‣ Height
‣ CenterX
‣ CenterY
‣ Baseline
Constant?
➢ Physical size or offset
Relation?
• Equal
• Less than or equal
• Greater than or equal
• If you want just "less than" or "greater than",
adjust the constant
Multiplier?
• Multiplier works on 2 objects.
• By Defaul Value is 1.
• It May be Integer ,Float and Ratio .
Priority
‣ Constraints with higher priority are satisfied before constraints with lower
priority.
‣ Default = UILayoutPriorityRequired (1000)
‣ Other predefined priorities
‣ UILayoutPriorityRequired = 1000
‣ UILayoutPriorityDefaultHigh = 750
‣ UILayoutPriorityDefaultLow = 250
‣ You can use any integer value between 0-1000
Adding Constraints
• Control-Dragging Constraints
To create a constraint between two views,
Control-click one of the views and drag to the
other.
When you release the mouse,
Interface Builder displays a HUD
menu with a list of possible
constraints.
• Using the Stack, Align, Pin and Resolve Tools
Interface Builder provides four Auto Layout tools in the bottom-right
corner of the Editor window. These are the Stack, Align, Pin, and Resolve
Auto Layout Issues tools.
• Align Tool
The Align tool lets you quickly align items in your layout. Select the items you want to align, and then
click the Align tool. Interface Builder presents a popover view containing a number of possible alignments.
• Pin Tool
The Pin tool lets you quickly define a view’s position relative to its neighbors or quickly define its
size. Select the item whose position or size you want to pin, and click the Pin tool. Interface
Builder presents a popover view containing a number of options.
• Resolve Auto Layout Issues Tool
The Resolve Auto Layout Issues tool provides a number of options for fixing common Auto
Layout issues. The options in the upper half of the menu affect only the currently selected views.
The options in the bottom half affect all views in the scene.
• Finding and Editing Constraints
After you’ve added a constraint, you need to be able to find it, view it, and edit it. There are a
number of options for accessing the constraints. Each option offers a unique method of
organizing and presenting the constraints.
• Viewing Constraints in the Canvas
The editor displays all the constraints affecting the currently selected view as colored lines
on the canvas. The shape, stroke type, and line color can tell you a lot about the current
state of the constraint.
Solid Lines - Solid lines represent required constraints (priority = 1000).
Dashed Lines - Dashed lines represent optional constraints (priority < 1000).
Red Lines - One of the items affected by this constraints has an error.
Orange Lines - Orange lines indicate that the frame of one of the items affected by
this constraint is not in the correct position based on the current set of constraints.
Blue Lines - The item’s frame is in the correct position as calculated by the Auto Layout engine.
Equal Badges - Interface Builder shows constraints that give two items an equal width or an
equal height as a separate bar for each item. Both bars are tagged with a blue badge containing an
equal (=) sign inside.
Greater-than-or-equal and less-than-or-equal badges - Interface Builder marks all constraints
representing greater-than-or-equal-to and less-than-or-equal-to relationships with a small blue
badge with a >= or <= symbol inside.
Listing Constraints in the Document Outline
• Interface Builder lists all the constraints in the document outline, grouping
them under the view that holds them.
• Also you could link constraint to properties of your controller as you do for
any other components. Just ctrl drag it into your code:
Finding Constraints in the Size Inspector
The Size inspector lists all the constraints
affecting the currently selected view. Required
constraints appear with a solid outline, and
optional constraints appear with a dashed outline.
The description lists important information about
the constraint.
Tips
➢ Where to add which constraints?
‣ When constraints only apply to 1 view (eg setting dimensions)
‣ create on view
‣ add to view
‣ When constraints apply to more than 1 view (eg pin one view to
another)
‣ Create on target view
‣ Add to common superview of both views (usually the same)
➢ Don't assume a view has a fixed size.
‣ (unless you give it a size constraint)
➢Create constraints between a view and its nearest neighbor.
➢Avoid giving views a fixed height or width.
➢Make sure all the views in your layout have meaningful names. This makes it
much easier to identify your views when using the tools.
➢ Try to minimalise the number of constraints .
‣ Solving takes time.
‣ More Constraints ,more Complex.
➢Create extra container view in Scroll view.
Tips
Tips
➢ Animating constraints
‣ Set constraints outside animation block.
‣ call layoutIfNeeded in animation.
‣ Make sure you do this on the correct “top level view” otherwise
nothing will animate!
self.offsetConstraint.constant = [self calculateOffset];
[UIView animationWithDuration:0.3 animations:^{
[self.view layoutIfNeeded];
}];

More Related Content

What's hot (13)

Geogebra 9
Geogebra 9Geogebra 9
Geogebra 9
 
Autolayout
AutolayoutAutolayout
Autolayout
 
tools
toolstools
tools
 
MEDIA TOOLS LL
MEDIA TOOLS    LLMEDIA TOOLS    LL
MEDIA TOOLS LL
 
Auto cad
Auto cadAuto cad
Auto cad
 
Create logo
Create logoCreate logo
Create logo
 
Google sketchup8
Google sketchup8Google sketchup8
Google sketchup8
 
solidworks
solidworkssolidworks
solidworks
 
AutoCAD Presentation
AutoCAD PresentationAutoCAD Presentation
AutoCAD Presentation
 
What is AutoCAD
What is AutoCADWhat is AutoCAD
What is AutoCAD
 
Roland Primer 3D Scanner
Roland Primer 3D ScannerRoland Primer 3D Scanner
Roland Primer 3D Scanner
 
Introduction to Rhino
Introduction to RhinoIntroduction to Rhino
Introduction to Rhino
 
NX_CAD
NX_CADNX_CAD
NX_CAD
 

Similar to Auto Layouts , NSLayoutConstraint, Traits in iOS

Application Development - Overview on Android OS
Application Development - Overview on Android OSApplication Development - Overview on Android OS
Application Development - Overview on Android OSPankaj Maheshwari
 
Autolayout primer
Autolayout primerAutolayout primer
Autolayout primerInferis
 
Ch4 creating user interfaces
Ch4 creating user interfacesCh4 creating user interfaces
Ch4 creating user interfacesShih-Hsiang Lin
 
WMP_MP02_revd(10092023).pptx
WMP_MP02_revd(10092023).pptxWMP_MP02_revd(10092023).pptx
WMP_MP02_revd(10092023).pptxfahmi324663
 
Lavacon 2014 responsive design in your hat
Lavacon 2014   responsive design in your hatLavacon 2014   responsive design in your hat
Lavacon 2014 responsive design in your hatNeil Perlin
 
AUTO CAD CIVIL ENGINEERING PPT REPORT
AUTO CAD CIVIL ENGINEERING PPT REPORTAUTO CAD CIVIL ENGINEERING PPT REPORT
AUTO CAD CIVIL ENGINEERING PPT REPORTDEEPAKKUMAR3980
 
Autocad 2016-tips-and-tricks-booklet-1
Autocad 2016-tips-and-tricks-booklet-1Autocad 2016-tips-and-tricks-booklet-1
Autocad 2016-tips-and-tricks-booklet-1Somanathan M
 
Advanced CSS.pptx
Advanced CSS.pptxAdvanced CSS.pptx
Advanced CSS.pptxDiyonaVas
 
Solidworks tips - First edition.pdf
Solidworks tips - First edition.pdfSolidworks tips - First edition.pdf
Solidworks tips - First edition.pdfZaheerAhmed905221
 
Building Native Experiences with Electron
Building Native Experiences with ElectronBuilding Native Experiences with Electron
Building Native Experiences with ElectronBen Gotow
 
android layouts
android layoutsandroid layouts
android layoutsDeepa Rani
 
Tk2323 lecture 2 ui
Tk2323 lecture 2   uiTk2323 lecture 2   ui
Tk2323 lecture 2 uiMengChun Lam
 

Similar to Auto Layouts , NSLayoutConstraint, Traits in iOS (20)

Application Development - Overview on Android OS
Application Development - Overview on Android OSApplication Development - Overview on Android OS
Application Development - Overview on Android OS
 
Acad12 tips online
Acad12 tips onlineAcad12 tips online
Acad12 tips online
 
Autolayout primer
Autolayout primerAutolayout primer
Autolayout primer
 
Ch4 creating user interfaces
Ch4 creating user interfacesCh4 creating user interfaces
Ch4 creating user interfaces
 
WMP_MP02_revd(10092023).pptx
WMP_MP02_revd(10092023).pptxWMP_MP02_revd(10092023).pptx
WMP_MP02_revd(10092023).pptx
 
Lavacon 2014 responsive design in your hat
Lavacon 2014   responsive design in your hatLavacon 2014   responsive design in your hat
Lavacon 2014 responsive design in your hat
 
AUTO CAD CIVIL ENGINEERING PPT REPORT
AUTO CAD CIVIL ENGINEERING PPT REPORTAUTO CAD CIVIL ENGINEERING PPT REPORT
AUTO CAD CIVIL ENGINEERING PPT REPORT
 
Autocad 2016-tips-and-tricks-booklet-1
Autocad 2016-tips-and-tricks-booklet-1Autocad 2016-tips-and-tricks-booklet-1
Autocad 2016-tips-and-tricks-booklet-1
 
Material design
Material designMaterial design
Material design
 
Ui 5
Ui   5Ui   5
Ui 5
 
Advanced CSS.pptx
Advanced CSS.pptxAdvanced CSS.pptx
Advanced CSS.pptx
 
Swift
SwiftSwift
Swift
 
Solidworks tips - First edition.pdf
Solidworks tips - First edition.pdfSolidworks tips - First edition.pdf
Solidworks tips - First edition.pdf
 
Building Native Experiences with Electron
Building Native Experiences with ElectronBuilding Native Experiences with Electron
Building Native Experiences with Electron
 
android layouts
android layoutsandroid layouts
android layouts
 
Adaptive Layout In iOS 8
Adaptive Layout In iOS 8Adaptive Layout In iOS 8
Adaptive Layout In iOS 8
 
Create New Android Layout
Create New Android LayoutCreate New Android Layout
Create New Android Layout
 
Prototyping + User Journeys
Prototyping + User JourneysPrototyping + User Journeys
Prototyping + User Journeys
 
Tk2323 lecture 2 ui
Tk2323 lecture 2   uiTk2323 lecture 2   ui
Tk2323 lecture 2 ui
 
Auto cad intro
Auto cad introAuto cad intro
Auto cad intro
 

Recently uploaded

Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 

Recently uploaded (20)

Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 

Auto Layouts , NSLayoutConstraint, Traits in iOS

  • 2. What is Auto Layout? Auto Layout is a new way to define dynamic GUIs. Before, we had autoresizing masks, that described how a subview will resize or move when its superview is resized. With Auto Layout you can do the same and also a lot more complicated GUIs quite easily.
  • 3. • Auto Layout minimizes your calculation. • Auto Layout design is indirect, but it’s also more flexible. • Auto Layout is driven by geometry. • Auto Layout focuses on relationships. • Support different screen sizes in your apps . • Auto Layout seeks optimal solutions. Features
  • 5. Constraint A Mathematical representation of a human : expressible statement "the left edge should be 20pt of the superviews left edge" view.left = (superview.left + 20) y = m * x+ c (y = attribute1 = view.left) (x = attribute2 = superview.left) (m = multiplier = 1) (c = constant = 20)
  • 6. Constraint ‣ Two items with an attribute ‣ Constant ‣ Relation ‣ Multiplier ‣ Priority level
  • 7. Attribute? ‣ Left ‣ Right ‣ Top ‣ Bottom ‣ Leading ~ left or right depending on language settings ‣ Trailing ~ right or left depending on language settings ‣ width ‣ Height ‣ CenterX ‣ CenterY ‣ Baseline
  • 8.
  • 9.
  • 11. Relation? • Equal • Less than or equal • Greater than or equal • If you want just "less than" or "greater than", adjust the constant
  • 12. Multiplier? • Multiplier works on 2 objects. • By Defaul Value is 1. • It May be Integer ,Float and Ratio .
  • 13. Priority ‣ Constraints with higher priority are satisfied before constraints with lower priority. ‣ Default = UILayoutPriorityRequired (1000) ‣ Other predefined priorities ‣ UILayoutPriorityRequired = 1000 ‣ UILayoutPriorityDefaultHigh = 750 ‣ UILayoutPriorityDefaultLow = 250 ‣ You can use any integer value between 0-1000
  • 14. Adding Constraints • Control-Dragging Constraints To create a constraint between two views, Control-click one of the views and drag to the other. When you release the mouse, Interface Builder displays a HUD menu with a list of possible constraints.
  • 15. • Using the Stack, Align, Pin and Resolve Tools Interface Builder provides four Auto Layout tools in the bottom-right corner of the Editor window. These are the Stack, Align, Pin, and Resolve Auto Layout Issues tools.
  • 16. • Align Tool The Align tool lets you quickly align items in your layout. Select the items you want to align, and then click the Align tool. Interface Builder presents a popover view containing a number of possible alignments.
  • 17. • Pin Tool The Pin tool lets you quickly define a view’s position relative to its neighbors or quickly define its size. Select the item whose position or size you want to pin, and click the Pin tool. Interface Builder presents a popover view containing a number of options.
  • 18. • Resolve Auto Layout Issues Tool The Resolve Auto Layout Issues tool provides a number of options for fixing common Auto Layout issues. The options in the upper half of the menu affect only the currently selected views. The options in the bottom half affect all views in the scene.
  • 19. • Finding and Editing Constraints After you’ve added a constraint, you need to be able to find it, view it, and edit it. There are a number of options for accessing the constraints. Each option offers a unique method of organizing and presenting the constraints. • Viewing Constraints in the Canvas The editor displays all the constraints affecting the currently selected view as colored lines on the canvas. The shape, stroke type, and line color can tell you a lot about the current state of the constraint. Solid Lines - Solid lines represent required constraints (priority = 1000). Dashed Lines - Dashed lines represent optional constraints (priority < 1000). Red Lines - One of the items affected by this constraints has an error. Orange Lines - Orange lines indicate that the frame of one of the items affected by this constraint is not in the correct position based on the current set of constraints.
  • 20. Blue Lines - The item’s frame is in the correct position as calculated by the Auto Layout engine. Equal Badges - Interface Builder shows constraints that give two items an equal width or an equal height as a separate bar for each item. Both bars are tagged with a blue badge containing an equal (=) sign inside. Greater-than-or-equal and less-than-or-equal badges - Interface Builder marks all constraints representing greater-than-or-equal-to and less-than-or-equal-to relationships with a small blue badge with a >= or <= symbol inside.
  • 21. Listing Constraints in the Document Outline • Interface Builder lists all the constraints in the document outline, grouping them under the view that holds them. • Also you could link constraint to properties of your controller as you do for any other components. Just ctrl drag it into your code:
  • 22. Finding Constraints in the Size Inspector The Size inspector lists all the constraints affecting the currently selected view. Required constraints appear with a solid outline, and optional constraints appear with a dashed outline. The description lists important information about the constraint.
  • 23. Tips ➢ Where to add which constraints? ‣ When constraints only apply to 1 view (eg setting dimensions) ‣ create on view ‣ add to view ‣ When constraints apply to more than 1 view (eg pin one view to another) ‣ Create on target view ‣ Add to common superview of both views (usually the same) ➢ Don't assume a view has a fixed size. ‣ (unless you give it a size constraint) ➢Create constraints between a view and its nearest neighbor.
  • 24. ➢Avoid giving views a fixed height or width. ➢Make sure all the views in your layout have meaningful names. This makes it much easier to identify your views when using the tools. ➢ Try to minimalise the number of constraints . ‣ Solving takes time. ‣ More Constraints ,more Complex. ➢Create extra container view in Scroll view. Tips
  • 25. Tips ➢ Animating constraints ‣ Set constraints outside animation block. ‣ call layoutIfNeeded in animation. ‣ Make sure you do this on the correct “top level view” otherwise nothing will animate! self.offsetConstraint.constant = [self calculateOffset]; [UIView animationWithDuration:0.3 animations:^{ [self.view layoutIfNeeded]; }];