SlideShare a Scribd company logo
VFL For Auto layout
Gagan Vishal Mishra
Apple provides VFL for handling the auto layout of the views added in a super
view. VFL stands for “Visual Format Language”. VFS allows the concise building
of the app layout using ASCII type art in string format.
Writing a single line code, VFL can specify multiple constraints. This tutorial will
be using a single below method
Objective-C:
+ (NSArray *) constraintsWithVisualFormat:(NSString *) format
options:(NSLayoutFormatOptions) opts metrics:(NSDictionary *) metrics
views:(NSDictionary *) views
Swift:
NSLayoutConstraint.constraints(withVisualFormat: String, options:
NSLayoutFormatOptions, metrics: [String: Any]? views: [String: Any])
We will be working on below method
NSLayoutConstraint.constraints(withVisualFormat: String, options:
NSLayoutFormatOptions, metrics: [String: Any]? views: [String: Any])
1. Views: This dictionary argument contains each view referred in layout string.
This dictionary contains a mapping of view to its name as below
let dicotionaryOfView = [“view1”: view1, “view2”, view2,.,...]
where view1, view2 are a subclass of UIView (label, image view etc.) In English ‘It
creates a dictionary where the name of your variable is the key and variable is the
object’.
2. Metrics: This is also a dictionary mapping between constants and their
corresponding keys. It can be used to centralized numbers that can be used in
layout operations. For example
let metricsDict = [“width”: 200, “height”:230,” padding”: 20,…..]
3. Options: It provides symmetricity & relation between views Added on super
view. For example, in a horizontal layout, it would be common to align the tops
and bottoms of all of the views in the VFL statement. For instance, we can
pass [. AlignAllTop |. AlignAllBottom] in the argument label. Apple provides
following option
• AlignAllCenterX
• AlignAllCenterY
• AlignAllLeading
• AlignAllTraining
• AlignAllLeft
• AlignAllRight
• AlignAllTop
• AlignAllBottom
• AlignAllBaseline
For more please go on Apple Documentation
4. Format: This is the focus point of the topic. Before explaining we must be
aware about the symbols in VFL
a) H : For horizontal layout. It is optional
b) V : For vertical Layout
c) | : Represent super view by a pipe
d) - : Standard spacing. Usually 8 points from super view.
e) -C- : Non-standard spacing by C (constant) points
f) == : Represents equality. Can be omitted.
g) >+ :Greater than or equal to option.
h) <= : Less than or equal to.
i) [] : Views are enclosed within square brackets.
j) @ : Use to represent priority of the added constraint. It has following
three options
i. 250 - Low
ii. 750 – High
iii. 1000 – Required
Don’t try to fit every facet of your layout into a single VFL string. All the method
does is parse the VFL, make individual constraints and return them as an
array. We have to be expressing at least one constraint though, otherwise the
string is meaningless. Below are some samples
1. |-[yourView]-| : yourView must have standard spacing from left & right.
2. |-[yourView] : yourView has standard spacing from left.
3. | [ yourView] : yourView must be align to the left.
4. |-20.0- [ yourView]-20-| : YourView must be 20 points spacing from left &
right edge of super view.
5. |- padding - [ yourView]- padding -| : YourView must be padding constant
points spacing from left & right edge of super view.
6. [ yourView(width)] : View must be 200.0 wide (width taken from metricsDict).
As we know ‘H’ optional so we cam omit. If we add H then expression will be
H:|[ yourView(width)]
7. V:|-[ yourView (50.0)] : yourView must have height of 50.0 points and
standard spacing from left edge of super view.
8. |- [ yourViewFirst(yourViewSecond)]-[yourViewSecond]-| : yourViewFirst
must be of width as yourViewSecond. yourViewFirst has standard spacing
from left edge of super-view. yourViewSecond has standard spacing from left
edge of super-view. yourViewFirst & yourViewSecond has standard spacing
between them.
9. -[yourView]- : ?? Nothing. Meaningless but why? Do you have answer 
Let’s have examples format string
H:|-[imageView(==viewInfo)]-20-[nameLabel(120)]-10@750-[viewInfo(>=50)]-|
In above example
1. H: Represents horizontal spacing.
2. |-[imageView Represents standard spacing i.e. should be of 8 points from
the left edge of super view.
3. (==viewInfo) Represents that imageView width must be equal to width of
viewInfo.
4. ]-20-[ nameLabel Represents imageView trailing edge must be of 20 points
from nameLabel.
5. (120) Represents nameLabel must be of width 120.
6. - 10@750- Represents nameLable should have trailing space of 20 from
viewInfo with priority High (i.e. 750)
7. viewInfo(>=50) Represents viewInfo must have width greater than or equal
to 50 points.
8. -| Represents standard spacing from right edge of super view.
Consider below example
V:|-(==padding)-[imageView]->=0-[button]-(==padding)-|
In above example padding is constant which is being passed as metrics
1. The top of the image view must be padding points from the top of the super
view
2. The bottom of the image view must be greater than or equal to 0 points from
the top of the button
3. The bottom of the button must be padding points from the bottom of the super
view.

More Related Content

What's hot

Power of functions in a typed world
Power of functions in a typed worldPower of functions in a typed world
Power of functions in a typed world
Debasish Ghosh
 
C programming session 05
C programming session 05C programming session 05
C programming session 05
Vivek Singh
 
Pointers in c v5 12102017 1
Pointers in c v5 12102017 1Pointers in c v5 12102017 1
Pointers in c v5 12102017 1
tanmaymodi4
 
C# Strings
C# StringsC# Strings
C# Strings
Hock Leng PUAH
 
Ch6 pointers (latest)
Ch6 pointers (latest)Ch6 pointers (latest)
Ch6 pointers (latest)
Hattori Sidek
 
CAD/CAM/CAE - Notes
CAD/CAM/CAE - NotesCAD/CAM/CAE - Notes
CAD/CAM/CAE - Notes
Learn With GeekAlign
 
Array 31.8.2020 updated
Array 31.8.2020 updatedArray 31.8.2020 updated
Array 31.8.2020 updated
vrgokila
 
Wireframe models
Wireframe modelsWireframe models
Wireframe models
Mohd Arif
 
Array&amp;string
Array&amp;stringArray&amp;string
Array&amp;string
chanchal ghosh
 
Ch5 array nota
Ch5 array notaCh5 array nota
Ch5 array nota
Hattori Sidek
 
An Introduction to Functional Programming at the Jozi Java User Group
An Introduction to Functional Programming at the Jozi Java User GroupAn Introduction to Functional Programming at the Jozi Java User Group
An Introduction to Functional Programming at the Jozi Java User Group
Andreas Pauley
 
Arrays
ArraysArrays
Arrays
Neeru Mittal
 
Algebraic Thinking for Evolution of Pure Functional Domain Models
Algebraic Thinking for Evolution of Pure Functional Domain ModelsAlgebraic Thinking for Evolution of Pure Functional Domain Models
Algebraic Thinking for Evolution of Pure Functional Domain Models
Debasish Ghosh
 
Excell vba
Excell vbaExcell vba
Excell vba
Abdul Alfiansyah
 
Introduction to programming c and data structures
Introduction to programming c and data structuresIntroduction to programming c and data structures
Introduction to programming c and data structures
Pradipta Mishra
 

What's hot (15)

Power of functions in a typed world
Power of functions in a typed worldPower of functions in a typed world
Power of functions in a typed world
 
C programming session 05
C programming session 05C programming session 05
C programming session 05
 
Pointers in c v5 12102017 1
Pointers in c v5 12102017 1Pointers in c v5 12102017 1
Pointers in c v5 12102017 1
 
C# Strings
C# StringsC# Strings
C# Strings
 
Ch6 pointers (latest)
Ch6 pointers (latest)Ch6 pointers (latest)
Ch6 pointers (latest)
 
CAD/CAM/CAE - Notes
CAD/CAM/CAE - NotesCAD/CAM/CAE - Notes
CAD/CAM/CAE - Notes
 
Array 31.8.2020 updated
Array 31.8.2020 updatedArray 31.8.2020 updated
Array 31.8.2020 updated
 
Wireframe models
Wireframe modelsWireframe models
Wireframe models
 
Array&amp;string
Array&amp;stringArray&amp;string
Array&amp;string
 
Ch5 array nota
Ch5 array notaCh5 array nota
Ch5 array nota
 
An Introduction to Functional Programming at the Jozi Java User Group
An Introduction to Functional Programming at the Jozi Java User GroupAn Introduction to Functional Programming at the Jozi Java User Group
An Introduction to Functional Programming at the Jozi Java User Group
 
Arrays
ArraysArrays
Arrays
 
Algebraic Thinking for Evolution of Pure Functional Domain Models
Algebraic Thinking for Evolution of Pure Functional Domain ModelsAlgebraic Thinking for Evolution of Pure Functional Domain Models
Algebraic Thinking for Evolution of Pure Functional Domain Models
 
Excell vba
Excell vbaExcell vba
Excell vba
 
Introduction to programming c and data structures
Introduction to programming c and data structuresIntroduction to programming c and data structures
Introduction to programming c and data structures
 

Similar to Visual Formatting Language in iOS

elm-d3 @ NYC D3.js Meetup (30 June, 2014)
elm-d3 @ NYC D3.js Meetup (30 June, 2014)elm-d3 @ NYC D3.js Meetup (30 June, 2014)
elm-d3 @ NYC D3.js Meetup (30 June, 2014)
Spiros
 
Ecs40 winter 2017 homework 3
Ecs40 winter 2017 homework 3Ecs40 winter 2017 homework 3
Ecs40 winter 2017 homework 3
JenniferBall44
 
CSS 3 Overview
CSS 3 OverviewCSS 3 Overview
CSS 3 Overview
Danilo Sousa
 
Odoo from 7.0 to 8.0 API
Odoo from 7.0 to 8.0 APIOdoo from 7.0 to 8.0 API
Odoo from 7.0 to 8.0 API
Mustufa Rangwala
 
Odoo - From v7 to v8: the new api
Odoo - From v7 to v8: the new apiOdoo - From v7 to v8: the new api
Odoo - From v7 to v8: the new api
Odoo
 
Java Fx Overview Tech Tour
Java Fx Overview Tech TourJava Fx Overview Tech Tour
Java Fx Overview Tech Tour
Carol McDonald
 
U5 JAVA.pptx
U5 JAVA.pptxU5 JAVA.pptx
U5 JAVA.pptx
madan r
 
Les11
Les11Les11
Manual Layout Revisited
Manual Layout RevisitedManual Layout Revisited
Manual Layout Revisited
gillygize
 
CSS and CSS3
CSS and CSS3CSS and CSS3
CSS and CSS3
Robyn Overstreet
 
Drupalcamp Leuven 2013 - Display Suite, the future of your display
Drupalcamp Leuven 2013 - Display Suite, the future of your displayDrupalcamp Leuven 2013 - Display Suite, the future of your display
Drupalcamp Leuven 2013 - Display Suite, the future of your display
Bram Goffings
 
The Java Fx Platform – A Java Developer’S Guide
The Java Fx Platform – A Java Developer’S GuideThe Java Fx Platform – A Java Developer’S Guide
The Java Fx Platform – A Java Developer’S Guide
Stephen Chin
 
8. Vectors data frames
8. Vectors data frames8. Vectors data frames
8. Vectors data frames
ExternalEvents
 
Drupal Views development
Drupal Views developmentDrupal Views development
Drupal Views development
OSInet
 
CPP-overviews notes variable data types notes
CPP-overviews notes variable data types notesCPP-overviews notes variable data types notes
CPP-overviews notes variable data types notes
SukhpreetSingh519414
 
C# 7 development
C# 7 developmentC# 7 development
C# 7 development
Fisnik Doko
 
CodeMash - Building Rich Apps with Groovy SwingBuilder
CodeMash - Building Rich Apps with Groovy SwingBuilderCodeMash - Building Rich Apps with Groovy SwingBuilder
CodeMash - Building Rich Apps with Groovy SwingBuilder
Andres Almiray
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
FALLEE31188
 
cppt-170218053903 (1).pptx
cppt-170218053903 (1).pptxcppt-170218053903 (1).pptx
cppt-170218053903 (1).pptx
WatchDog13
 
Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...
Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...
Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...
Carl Brown
 

Similar to Visual Formatting Language in iOS (20)

elm-d3 @ NYC D3.js Meetup (30 June, 2014)
elm-d3 @ NYC D3.js Meetup (30 June, 2014)elm-d3 @ NYC D3.js Meetup (30 June, 2014)
elm-d3 @ NYC D3.js Meetup (30 June, 2014)
 
Ecs40 winter 2017 homework 3
Ecs40 winter 2017 homework 3Ecs40 winter 2017 homework 3
Ecs40 winter 2017 homework 3
 
CSS 3 Overview
CSS 3 OverviewCSS 3 Overview
CSS 3 Overview
 
Odoo from 7.0 to 8.0 API
Odoo from 7.0 to 8.0 APIOdoo from 7.0 to 8.0 API
Odoo from 7.0 to 8.0 API
 
Odoo - From v7 to v8: the new api
Odoo - From v7 to v8: the new apiOdoo - From v7 to v8: the new api
Odoo - From v7 to v8: the new api
 
Java Fx Overview Tech Tour
Java Fx Overview Tech TourJava Fx Overview Tech Tour
Java Fx Overview Tech Tour
 
U5 JAVA.pptx
U5 JAVA.pptxU5 JAVA.pptx
U5 JAVA.pptx
 
Les11
Les11Les11
Les11
 
Manual Layout Revisited
Manual Layout RevisitedManual Layout Revisited
Manual Layout Revisited
 
CSS and CSS3
CSS and CSS3CSS and CSS3
CSS and CSS3
 
Drupalcamp Leuven 2013 - Display Suite, the future of your display
Drupalcamp Leuven 2013 - Display Suite, the future of your displayDrupalcamp Leuven 2013 - Display Suite, the future of your display
Drupalcamp Leuven 2013 - Display Suite, the future of your display
 
The Java Fx Platform – A Java Developer’S Guide
The Java Fx Platform – A Java Developer’S GuideThe Java Fx Platform – A Java Developer’S Guide
The Java Fx Platform – A Java Developer’S Guide
 
8. Vectors data frames
8. Vectors data frames8. Vectors data frames
8. Vectors data frames
 
Drupal Views development
Drupal Views developmentDrupal Views development
Drupal Views development
 
CPP-overviews notes variable data types notes
CPP-overviews notes variable data types notesCPP-overviews notes variable data types notes
CPP-overviews notes variable data types notes
 
C# 7 development
C# 7 developmentC# 7 development
C# 7 development
 
CodeMash - Building Rich Apps with Groovy SwingBuilder
CodeMash - Building Rich Apps with Groovy SwingBuilderCodeMash - Building Rich Apps with Groovy SwingBuilder
CodeMash - Building Rich Apps with Groovy SwingBuilder
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
cppt-170218053903 (1).pptx
cppt-170218053903 (1).pptxcppt-170218053903 (1).pptx
cppt-170218053903 (1).pptx
 
Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...
Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...
Advanced, Composable Collection Views, From CocoaCoders meetup Austin Feb 12,...
 

More from Gagan Vishal Mishra

iOS Versions history
iOS Versions historyiOS Versions history
iOS Versions history
Gagan Vishal Mishra
 
Core data optimization
Core data optimizationCore data optimization
Core data optimization
Gagan Vishal Mishra
 
Jenkins CI/CD setup for iOS in Mac OSX
Jenkins CI/CD setup for iOS in Mac OSXJenkins CI/CD setup for iOS in Mac OSX
Jenkins CI/CD setup for iOS in Mac OSX
Gagan Vishal Mishra
 
Linking between JIRA & GIT, Smart Commit Command
Linking between JIRA & GIT, Smart Commit Command Linking between JIRA & GIT, Smart Commit Command
Linking between JIRA & GIT, Smart Commit Command
Gagan Vishal Mishra
 
Backbase CXP Manager Setup
Backbase CXP Manager SetupBackbase CXP Manager Setup
Backbase CXP Manager Setup
Gagan Vishal Mishra
 
Dynamic databinding
Dynamic databindingDynamic databinding
Dynamic databinding
Gagan Vishal Mishra
 
Search API
Search APISearch API
IBDesignable & IBInspectible
IBDesignable & IBInspectibleIBDesignable & IBInspectible
IBDesignable & IBInspectible
Gagan Vishal Mishra
 
Core Data Performance Guide Line
Core Data Performance Guide LineCore Data Performance Guide Line
Core Data Performance Guide Line
Gagan Vishal Mishra
 

More from Gagan Vishal Mishra (9)

iOS Versions history
iOS Versions historyiOS Versions history
iOS Versions history
 
Core data optimization
Core data optimizationCore data optimization
Core data optimization
 
Jenkins CI/CD setup for iOS in Mac OSX
Jenkins CI/CD setup for iOS in Mac OSXJenkins CI/CD setup for iOS in Mac OSX
Jenkins CI/CD setup for iOS in Mac OSX
 
Linking between JIRA & GIT, Smart Commit Command
Linking between JIRA & GIT, Smart Commit Command Linking between JIRA & GIT, Smart Commit Command
Linking between JIRA & GIT, Smart Commit Command
 
Backbase CXP Manager Setup
Backbase CXP Manager SetupBackbase CXP Manager Setup
Backbase CXP Manager Setup
 
Dynamic databinding
Dynamic databindingDynamic databinding
Dynamic databinding
 
Search API
Search APISearch API
Search API
 
IBDesignable & IBInspectible
IBDesignable & IBInspectibleIBDesignable & IBInspectible
IBDesignable & IBInspectible
 
Core Data Performance Guide Line
Core Data Performance Guide LineCore Data Performance Guide Line
Core Data Performance Guide Line
 

Recently uploaded

How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Data structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdfData structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdf
TIPNGVN2
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 

Recently uploaded (20)

How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Data structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdfData structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdf
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 

Visual Formatting Language in iOS

  • 1. VFL For Auto layout Gagan Vishal Mishra
  • 2. Apple provides VFL for handling the auto layout of the views added in a super view. VFL stands for “Visual Format Language”. VFS allows the concise building of the app layout using ASCII type art in string format. Writing a single line code, VFL can specify multiple constraints. This tutorial will be using a single below method Objective-C: + (NSArray *) constraintsWithVisualFormat:(NSString *) format options:(NSLayoutFormatOptions) opts metrics:(NSDictionary *) metrics views:(NSDictionary *) views Swift: NSLayoutConstraint.constraints(withVisualFormat: String, options: NSLayoutFormatOptions, metrics: [String: Any]? views: [String: Any])
  • 3. We will be working on below method NSLayoutConstraint.constraints(withVisualFormat: String, options: NSLayoutFormatOptions, metrics: [String: Any]? views: [String: Any]) 1. Views: This dictionary argument contains each view referred in layout string. This dictionary contains a mapping of view to its name as below let dicotionaryOfView = [“view1”: view1, “view2”, view2,.,...] where view1, view2 are a subclass of UIView (label, image view etc.) In English ‘It creates a dictionary where the name of your variable is the key and variable is the object’. 2. Metrics: This is also a dictionary mapping between constants and their corresponding keys. It can be used to centralized numbers that can be used in layout operations. For example let metricsDict = [“width”: 200, “height”:230,” padding”: 20,…..]
  • 4. 3. Options: It provides symmetricity & relation between views Added on super view. For example, in a horizontal layout, it would be common to align the tops and bottoms of all of the views in the VFL statement. For instance, we can pass [. AlignAllTop |. AlignAllBottom] in the argument label. Apple provides following option • AlignAllCenterX • AlignAllCenterY • AlignAllLeading • AlignAllTraining • AlignAllLeft • AlignAllRight • AlignAllTop • AlignAllBottom • AlignAllBaseline For more please go on Apple Documentation
  • 5. 4. Format: This is the focus point of the topic. Before explaining we must be aware about the symbols in VFL a) H : For horizontal layout. It is optional b) V : For vertical Layout c) | : Represent super view by a pipe d) - : Standard spacing. Usually 8 points from super view. e) -C- : Non-standard spacing by C (constant) points f) == : Represents equality. Can be omitted. g) >+ :Greater than or equal to option. h) <= : Less than or equal to. i) [] : Views are enclosed within square brackets. j) @ : Use to represent priority of the added constraint. It has following three options i. 250 - Low ii. 750 – High iii. 1000 – Required
  • 6. Don’t try to fit every facet of your layout into a single VFL string. All the method does is parse the VFL, make individual constraints and return them as an array. We have to be expressing at least one constraint though, otherwise the string is meaningless. Below are some samples 1. |-[yourView]-| : yourView must have standard spacing from left & right. 2. |-[yourView] : yourView has standard spacing from left. 3. | [ yourView] : yourView must be align to the left. 4. |-20.0- [ yourView]-20-| : YourView must be 20 points spacing from left & right edge of super view. 5. |- padding - [ yourView]- padding -| : YourView must be padding constant points spacing from left & right edge of super view. 6. [ yourView(width)] : View must be 200.0 wide (width taken from metricsDict). As we know ‘H’ optional so we cam omit. If we add H then expression will be H:|[ yourView(width)] 7. V:|-[ yourView (50.0)] : yourView must have height of 50.0 points and standard spacing from left edge of super view.
  • 7. 8. |- [ yourViewFirst(yourViewSecond)]-[yourViewSecond]-| : yourViewFirst must be of width as yourViewSecond. yourViewFirst has standard spacing from left edge of super-view. yourViewSecond has standard spacing from left edge of super-view. yourViewFirst & yourViewSecond has standard spacing between them. 9. -[yourView]- : ?? Nothing. Meaningless but why? Do you have answer 
  • 8. Let’s have examples format string H:|-[imageView(==viewInfo)]-20-[nameLabel(120)]-10@750-[viewInfo(>=50)]-| In above example 1. H: Represents horizontal spacing. 2. |-[imageView Represents standard spacing i.e. should be of 8 points from the left edge of super view. 3. (==viewInfo) Represents that imageView width must be equal to width of viewInfo. 4. ]-20-[ nameLabel Represents imageView trailing edge must be of 20 points from nameLabel. 5. (120) Represents nameLabel must be of width 120. 6. - 10@750- Represents nameLable should have trailing space of 20 from viewInfo with priority High (i.e. 750) 7. viewInfo(>=50) Represents viewInfo must have width greater than or equal to 50 points. 8. -| Represents standard spacing from right edge of super view.
  • 9. Consider below example V:|-(==padding)-[imageView]->=0-[button]-(==padding)-| In above example padding is constant which is being passed as metrics 1. The top of the image view must be padding points from the top of the super view 2. The bottom of the image view must be greater than or equal to 0 points from the top of the button 3. The bottom of the button must be padding points from the bottom of the super view.

Editor's Notes

  1. https://developer.apple.com/documentation/uikit/nslayoutconstraint#//apple_ref/c/tdef/NSLayoutFormatOptions