SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Downloaden Sie, um offline zu lesen
Auto Layout
(Xcode 5)
Seeing this view with all the lines will make
you freak out.
Xcode 4
There is a rumor that iPhone 6 will have a new size 4.7 and 5.5 inch.
Imagine how you will handle the different screen sizes
Autoresizing Mask
Autoresizing mask can help us
with our views but it’s too
limited.
Auto Layout To The Rescue!
Auto Layout is a system that lets you lay out
your app’s user interface by creating a
mathematical description of the relationships
between the elements.
You define these relationships in terms of
constraints either on individual elements, or
between sets of elements.
What is Auto Layout?
1. It allows for more flexible layouts when
dealing with multiple screen sizes, interface
orientations, and languages.
2. You won’t do a lot of coding for layout.
Why use Auto Layout?
Auto Layout on Xcode 5
Auto Layout is enabled by default. When
you add an object in your xib in Xcode 4,
constraints(T-bars) appear immediately. We
tend to disable auto layout because it looks
frustrating.
Apple knows it. That’s why in Xcode 5, even
though Auto Layout is enabled, and you’re
not creating any constraints, the T-bars will
not appear.
Auto Layout on Xcode 5
In Auto Layout, if you set your button in that position and added
constraints, you are telling xcode that the button is on the top-
right position of the view, regardless of its orientation or screen
size.
When setting the button position without auto-layout, you can set its
position in the xib. But what if you change the orientation to
landscape or you have a different screen size? You have to write
code to set its position.
Add Constraints
There are 3 ways to add constraints.
● From the toolbar
● Using Interface Builder
● By Dragging Objects
Toolbar
Editor Menu is used for
auto layout. Just select
the object on the view
and select from the editor
which constraints you
want to add.
Interface Builder
On the bottom part of IB, there are
four buttons for auto layout.
● Align
● Pin
● Resolve Auto Layout Issues
● Resizing Behavior
It has the same content as the
Editor Menu
Interface Builder
Align
Interface Builder
Pin
Interface Builder
Resolve Auto Layout Issues
Interface Builder
Resizing Behavior
Dragging Object
You can also add
constraints by dragging
the object to another
object, then a menu will
popup and you can select
which constraints you
want.
Orange and Blue
Orange Line
When you add constraints on your object,
an orange line will appear. This means that
xcode cannot identify or compute the
position of that object. Xcode needs more
constraints to get more information on that
object.
Blue Line
If the T-bar is blue, it means that xcode has
sufficient information about the object.
Orange Line
When you manually adjust the position of
an object that already has constraints, an
orange line will appear. This means that
there is an error. You can solve this by
using the Resolve Auto Layout in Editor
Menu.
Select Editor > Resolve Auto Layout Issues
> Update Constraints
Reference:
https://developer.apple.com/videos/wwdc/2013/
http://www.raywenderlich.com/50317/beginning-auto-
layout-tutorial-in-ios-7-part-1
http://www.raywenderlich.com/50319/beginning-auto-
layout-tutorial-in-ios-7-part-2

Weitere ähnliche Inhalte

Ähnlich wie Auto Layout on Xcode 5

iOS App Development with Storyboard
iOS App Development with StoryboardiOS App Development with Storyboard
iOS App Development with Storyboard
Babul Mirdha
 
Beginning iOS 7 Development Exploring the iOS SDKby Jack .docx
Beginning iOS 7 Development Exploring the iOS SDKby Jack .docxBeginning iOS 7 Development Exploring the iOS SDKby Jack .docx
Beginning iOS 7 Development Exploring the iOS SDKby Jack .docx
taitcandie
 
Beginning iOS 7 Development Exploring the iOS SDKby Jack .docx
Beginning iOS 7 Development Exploring the iOS SDKby Jack .docxBeginning iOS 7 Development Exploring the iOS SDKby Jack .docx
Beginning iOS 7 Development Exploring the iOS SDKby Jack .docx
ikirkton
 
Session 8 - Xcode 5 and interface builder for iOS 7 application
Session 8 - Xcode 5 and interface builder for iOS 7 applicationSession 8 - Xcode 5 and interface builder for iOS 7 application
Session 8 - Xcode 5 and interface builder for iOS 7 application
Vu Tran Lam
 
How to create ui using droid draw
How to create ui using droid drawHow to create ui using droid draw
How to create ui using droid draw
info_zybotech
 
Plan601 e session 2 demob
Plan601 e session 2 demobPlan601 e session 2 demob
Plan601 e session 2 demob
rkottam
 
plan601 e session 2 demo
plan601 e session 2 demoplan601 e session 2 demo
plan601 e session 2 demo
rkottam
 
iOS 7 UI Transition Guide
iOS 7 UI Transition GuideiOS 7 UI Transition Guide
iOS 7 UI Transition Guide
Evgeny Belyaev
 
Auto cad 2007-tutorial
Auto cad 2007-tutorialAuto cad 2007-tutorial
Auto cad 2007-tutorial
Syed Javeed
 
Plan601 e session 2 demo
Plan601 e session 2 demoPlan601 e session 2 demo
Plan601 e session 2 demo
rkottamasu
 
Mobile Application Development -Lecture 07 & 08.pdf
Mobile Application Development -Lecture 07 & 08.pdfMobile Application Development -Lecture 07 & 08.pdf
Mobile Application Development -Lecture 07 & 08.pdf
AbdullahMunir32
 
Autocad 2013-tips-and-tricks-2
Autocad 2013-tips-and-tricks-2Autocad 2013-tips-and-tricks-2
Autocad 2013-tips-and-tricks-2
Bala Chandar
 

Ähnlich wie Auto Layout on Xcode 5 (20)

Mobile Programming - 3 Rows, Column and Basic Sizing
Mobile Programming - 3 Rows, Column and Basic SizingMobile Programming - 3 Rows, Column and Basic Sizing
Mobile Programming - 3 Rows, Column and Basic Sizing
 
IOS Swift language 1st Tutorial
IOS Swift language 1st TutorialIOS Swift language 1st Tutorial
IOS Swift language 1st Tutorial
 
iOS App Development with Storyboard
iOS App Development with StoryboardiOS App Development with Storyboard
iOS App Development with Storyboard
 
Beginning iOS 7 Development Exploring the iOS SDKby Jack .docx
Beginning iOS 7 Development Exploring the iOS SDKby Jack .docxBeginning iOS 7 Development Exploring the iOS SDKby Jack .docx
Beginning iOS 7 Development Exploring the iOS SDKby Jack .docx
 
Beginning iOS 7 Development Exploring the iOS SDKby Jack .docx
Beginning iOS 7 Development Exploring the iOS SDKby Jack .docxBeginning iOS 7 Development Exploring the iOS SDKby Jack .docx
Beginning iOS 7 Development Exploring the iOS SDKby Jack .docx
 
Session 8 - Xcode 5 and interface builder for iOS 7 application
Session 8 - Xcode 5 and interface builder for iOS 7 applicationSession 8 - Xcode 5 and interface builder for iOS 7 application
Session 8 - Xcode 5 and interface builder for iOS 7 application
 
iOS 7 Transition guide
iOS 7 Transition guideiOS 7 Transition guide
iOS 7 Transition guide
 
How to create ui using droid draw
How to create ui using droid drawHow to create ui using droid draw
How to create ui using droid draw
 
Plan601 e session 2 demob
Plan601 e session 2 demobPlan601 e session 2 demob
Plan601 e session 2 demob
 
plan601 e session 2 demo
plan601 e session 2 demoplan601 e session 2 demo
plan601 e session 2 demo
 
iOS UI best practices
iOS UI best practicesiOS UI best practices
iOS UI best practices
 
Autocad 2007 Workbook Tutorial
Autocad 2007 Workbook TutorialAutocad 2007 Workbook Tutorial
Autocad 2007 Workbook Tutorial
 
iOS 7 UI Transition Guide
iOS 7 UI Transition GuideiOS 7 UI Transition Guide
iOS 7 UI Transition Guide
 
Swift
SwiftSwift
Swift
 
Auto cad 2007-tutorial
Auto cad 2007-tutorialAuto cad 2007-tutorial
Auto cad 2007-tutorial
 
Plan601 e session 2 demo
Plan601 e session 2 demoPlan601 e session 2 demo
Plan601 e session 2 demo
 
Mobile Application Development -Lecture 07 & 08.pdf
Mobile Application Development -Lecture 07 & 08.pdfMobile Application Development -Lecture 07 & 08.pdf
Mobile Application Development -Lecture 07 & 08.pdf
 
Sketchup-Handbook.pdf
Sketchup-Handbook.pdfSketchup-Handbook.pdf
Sketchup-Handbook.pdf
 
Mobile Programming - 6 Textfields, Button, Showing Snackbars and Lists
Mobile Programming - 6 Textfields, Button, Showing Snackbars and ListsMobile Programming - 6 Textfields, Button, Showing Snackbars and Lists
Mobile Programming - 6 Textfields, Button, Showing Snackbars and Lists
 
Autocad 2013-tips-and-tricks-2
Autocad 2013-tips-and-tricks-2Autocad 2013-tips-and-tricks-2
Autocad 2013-tips-and-tricks-2
 

Mehr von KLabCyscorpions-TechBlog

Mehr von KLabCyscorpions-TechBlog (13)

Object Calisthenics in Objective-C
Object Calisthenics in Objective-CObject Calisthenics in Objective-C
Object Calisthenics in Objective-C
 
Code Review for iOS
Code Review for iOSCode Review for iOS
Code Review for iOS
 
Object Calisthenics
Object CalisthenicsObject Calisthenics
Object Calisthenics
 
Why You're A Bad PHP Programmer
Why You're A Bad PHP ProgrammerWhy You're A Bad PHP Programmer
Why You're A Bad PHP Programmer
 
Redis Set Go
Redis Set GoRedis Set Go
Redis Set Go
 
Redis Beyond
Redis BeyondRedis Beyond
Redis Beyond
 
X-Debug in Php Storm
X-Debug in Php StormX-Debug in Php Storm
X-Debug in Php Storm
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
Php + MySql Optimization
Php + MySql OptimizationPhp + MySql Optimization
Php + MySql Optimization
 
Mysql Optimization
Mysql OptimizationMysql Optimization
Mysql Optimization
 
MVC Web Application
MVC Web ApplicationMVC Web Application
MVC Web Application
 
AfNetworking vs. Native + Caching
AfNetworking vs. Native + CachingAfNetworking vs. Native + Caching
AfNetworking vs. Native + Caching
 
Bash
BashBash
Bash
 

Kürzlich hochgeladen

Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 

Kürzlich hochgeladen (20)

Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 

Auto Layout on Xcode 5