SlideShare une entreprise Scribd logo
1  sur  9
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.

Contenu connexe

Tendances

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 worldDebasish Ghosh
 
C programming session 05
C programming session 05C programming session 05
C programming session 05Vivek Singh
 
Pointers in c v5 12102017 1
Pointers in c v5 12102017 1Pointers in c v5 12102017 1
Pointers in c v5 12102017 1tanmaymodi4
 
Ch6 pointers (latest)
Ch6 pointers (latest)Ch6 pointers (latest)
Ch6 pointers (latest)Hattori Sidek
 
Array 31.8.2020 updated
Array 31.8.2020 updatedArray 31.8.2020 updated
Array 31.8.2020 updatedvrgokila
 
Wireframe models
Wireframe modelsWireframe models
Wireframe modelsMohd Arif
 
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 GroupAndreas Pauley
 
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 ModelsDebasish Ghosh
 
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 structuresPradipta Mishra
 

Tendances (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
 

Similaire à 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 3JenniferBall44
 
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 apiOdoo
 
Java Fx Overview Tech Tour
Java Fx Overview Tech TourJava Fx Overview Tech Tour
Java Fx Overview Tech TourCarol McDonald
 
U5 JAVA.pptx
U5 JAVA.pptxU5 JAVA.pptx
U5 JAVA.pptxmadan r
 
Manual Layout Revisited
Manual Layout RevisitedManual Layout Revisited
Manual Layout Revisitedgillygize
 
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 displayBram 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 GuideStephen Chin
 
8. Vectors data frames
8. Vectors data frames8. Vectors data frames
8. Vectors data framesExternalEvents
 
Drupal Views development
Drupal Views developmentDrupal Views development
Drupal Views developmentOSInet
 
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 notesSukhpreetSingh519414
 
C# 7 development
C# 7 developmentC# 7 development
C# 7 developmentFisnik 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 SwingBuilderAndres Almiray
 
cppt-170218053903 (1).pptx
cppt-170218053903 (1).pptxcppt-170218053903 (1).pptx
cppt-170218053903 (1).pptxWatchDog13
 
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
 

Similaire à 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,...
 

Plus de Gagan Vishal Mishra

Plus de 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
 

Dernier

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 

Dernier (20)

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.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.

Notes de l'éditeur

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