SlideShare a Scribd company logo
Cocoa Text
    Chad Sellers
Useful Fruit Software
      9/8/2010
What is Cocoa Text
What is Cocoa Text
• High level text
  framework
What is Cocoa Text
• High level text   Cocoa Text
  framework
What is Cocoa Text
• High level text           Cocoa Text
  framework
• As opposed to Core Text
What is Cocoa Text
• High level text           Cocoa Text
  framework
• As opposed to Core Text


                            Core Text
What is Cocoa Text
• High level text           Cocoa Text
                            • Pre-made widgets
  framework                 • Lots of UI

• As opposed to Core Text


                            Core Text
What is Cocoa Text
• High level text           Cocoa Text
                            • Pre-made widgets
  framework                 • Lots of UI

• As opposed to Core Text


                            Core Text
                             • Do it yourself
Text Rendering
Text Rendering
•   Fonts
Text Rendering
•   Fonts

•   Bold/Underline/Italics
Text Rendering
•   Fonts

•   Bold/Underline/Italics

•   Colors
Text Rendering
•   Fonts

•   Bold/Underline/Italics

•   Colors

•   Kerning
Text Rendering
•   Fonts

•   Bold/Underline/Italics

•   Colors

•   Kerning

•   Ligature (fi fi)
Text Rendering
•   Fonts

•   Bold/Underline/Italics

•   Colors

•   Kerning

•   Ligature (fi fi)

•   Baseline
Text Rendering
•   Fonts                    •   Inline attachments

•   Bold/Underline/Italics

•   Colors

•   Kerning

•   Ligature (fi fi)

•   Baseline
Much more
Much more
•   Layout
Much more
•   Layout

•   Editing
Much more
•   Layout

•   Editing

    •   cursor
Much more
•   Layout

•   Editing

    •   cursor

    •   input handling
Much more
•   Layout

•   Editing

    •   cursor

    •   input handling

•   Spelling/Grammar
Much more
•   Layout

•   Editing

    •   cursor

    •   input handling

•   Spelling/Grammar

•   Finding
Much more
•   Layout               •   Substitutions

•   Editing

    •   cursor

    •   input handling

•   Spelling/Grammar

•   Finding
Much more
•   Layout               •   Substitutions

•   Editing              •   Transformations

    •   cursor

    •   input handling

•   Spelling/Grammar

•   Finding
Much more
•   Layout               •   Substitutions

•   Editing              •   Transformations

    •   cursor           •   Speech

    •   input handling

•   Spelling/Grammar

•   Finding
Much more
•   Layout               •   Substitutions

•   Editing              •   Transformations

    •   cursor           •   Speech

    •   input handling   •   Dictionary

•   Spelling/Grammar

•   Finding
Much more
•   Layout               •   Substitutions

•   Editing              •   Transformations

    •   cursor           •   Speech

    •   input handling   •   Dictionary

•   Spelling/Grammar     •   and more

•   Finding
Sample code
Sample code


  TextEdit
/Developer/Examples/TextEdit
NSString
NSString
• Plain text
NSString
• Plain text
• Immutable
NSString
• Plain text
• Immutable
 • NSMutableString isn’t
NSString
• Plain text
• Immutable
 • NSMutableString isn’t
• Literal - @”literal”
NSString
• Plain text
• Immutable
 • NSMutableString isn’t
• Literal - @”literal”
• Handles encodings
NSString
• Plain text
• Immutable
 • NSMutableString isn’t
• Literal - @”literal”
• Handles encodings
• Methods to split/join/etc.
NSString
• Plain text
• Immutable
 • NSMutableString isn’t
• Literal - @”literal”
• Handles encodings
• Methods to split/join/etc.
  •   - (NSString *)substringWithRange:(NSRange)aRange
NSString
• Plain text
• Immutable
 • NSMutableString isn’t
• Literal - @”literal”
• Handles encodings
• Methods to split/join/etc.
  •   - (NSString *)substringWithRange:(NSRange)aRange

  •   - (NSString *)stringByAppendingPathComponent:(NSString *)aString
NSAttributedString
NSAttributedString
• Rich text
NSAttributedString
• Rich text
• Attributes applied over a range
NSAttributedString
• Rich text
• Attributes applied over a range
• Foundation version not too useful alone
NSAttributedString
• Rich text
• Attributes applied over a range
• Foundation version not too useful alone
• AppKit Additions make it useful
NSAttributedString
• Rich text
• Attributes applied over a range
• Foundation version not too useful alone
• AppKit Additions make it useful
 • Adds useful attributes (e.g. NSFontAttributeName)
NSAttributedString
• Rich text
• Attributes applied over a range
• Foundation version not too useful alone
• AppKit Additions make it useful
 • Adds useful attributes (e.g. NSFontAttributeName)
• Methods for reading/writing common formats
NSAttributedString
• Rich text
• Attributes applied over a range
• Foundation version not too useful alone
• AppKit Additions make it useful
 • Adds useful attributes (e.g. NSFontAttributeName)
• Methods for reading/writing common formats
 • RTF/RTFD, HTML, Word Doc, Open XML, OpenDoc
Attributes
Attributes
Attributes make strings fun!
Attributes
         Attributes make strings fun!

NSForegroundColorAttributeName
       [NSColor redColor]
Attributes
         Attributes make strings                           fun!


NSForegroundColorAttributeName             NSFontAttributeName
       [NSColor redColor]         [NSFont fontWithName:@”Monaco” size:48]
Attributes
         Attributes make strings                                               fun!


NSForegroundColorAttributeName                                 NSFontAttributeName
       [NSColor redColor]                             [NSFont fontWithName:@”Monaco” size:48]




                                    NSUnderlineStyleAttributeName
                            [NSNumber numberWithInt:NSUnderlineStyleDouble]
Attributes
         Attributes make strings                                               fun!


NSForegroundColorAttributeName                                 NSFontAttributeName
       [NSColor redColor]                             [NSFont fontWithName:@”Monaco” size:48]




                                    NSUnderlineStyleAttributeName
                            [NSNumber numberWithInt:NSUnderlineStyleDouble]
NSMutableAttributedString
NSMutableAttributedString
  • Mutable version of NSAttributedString
NSMutableAttributedString
  • Mutable version of NSAttributedString
  • Also has AppKit additions
NSTextStorage
NSTextStorage
• Subclass of NSMutableAttributedString
NSTextStorage
• Subclass of NSMutableAttributedString
• Main text storage class used in Cocoa Text
NSTextStorage
• Subclass of NSMutableAttributedString
• Main text storage class used in Cocoa Text
• Manages NSLayoutManagers
NSTextStorage
• Subclass of NSMutableAttributedString
• Main text storage class used in Cocoa Text
• Manages NSLayoutManagers
 • which layout text into text containers
NSTextView
NSTextView
• View for displaying/editing rich text
NSTextView
• View for displaying/editing rich text
• Contains NSTextContainer
NSTextView
• View for displaying/editing rich text
• Contains NSTextContainer
 • NSLayoutManager lays out text here
NSTextView
• View for displaying/editing rich text
• Contains NSTextContainer
 • NSLayoutManager lays out text here
• Lots of methods ready to be wired up in IB
NSTextView
• View for displaying/editing rich text
• Contains NSTextContainer
 • NSLayoutManager lays out text here
• Lots of methods ready to be wired up in IB
 • IB even has prebuilt menus to use them
Customizing NSTextView
Customizing NSTextView
 • First stop - delegate methods
Customizing NSTextView
 • First stop - delegate methods
  • From NSTextViewDelegate and
     NSTextDelegate protocols
Customizing NSTextView
 • First stop - delegate methods
  • From NSTextViewDelegate and
     NSTextDelegate protocols
 • Last stop - subclass
NSTextField
NSTextField
• Lighter weight than NSTextView
NSTextField
• Lighter weight than NSTextView
• Subclass of NSControl, not NSText
NSTextField
• Lighter weight than NSTextView
• Subclass of NSControl, not NSText
• Generally single line
NSTextField
• Lighter weight than NSTextView
• Subclass of NSControl, not NSText
• Generally single line
• No layout manager or text container
UITextView
UITextView
• Much simpler than NSTextView
UITextView
• Much simpler than NSTextView
 • 10 properties and 2 methods
UITextView
• Much simpler than NSTextView
 • 10 properties and 2 methods
 • vs. NSTextView/NSText’s 258 methods
UITextView
• Much simpler than NSTextView
 • 10 properties and 2 methods
 • vs. NSTextView/NSText’s 258 methods
• Limited simple styling
UITextView
• Much simpler than NSTextView
 • 10 properties and 2 methods
 • vs. NSTextView/NSText’s 258 methods
• Limited simple styling
 • a few non-ranged attributes
UITextView
• Much simpler than NSTextView
 • 10 properties and 2 methods
 • vs. NSTextView/NSText’s 258 methods
• Limited simple styling
 • a few non-ranged attributes
• Apple recommends UIWebView for
  complex styling
NSAttributedString on iOS
NSAttributedString on iOS
  • Available on iOS 3.2+
NSAttributedString on iOS
  • Available on iOS 3.2+
  • For use with Core Text
NSAttributedString on iOS
  • Available on iOS 3.2+
  • For use with Core Text
  • No AppKit Additions
NSAttributedString on iOS
  • Available on iOS 3.2+
  • For use with Core Text
  • No AppKit Additions
  • Use Core Text attributes
Demo

More Related Content

PDF
Css1 properties
PPTX
Css 3
PPTX
Css 3
PDF
Scala.io
PDF
ParisJS #11 : Sass & Compass
KEY
Developing With Django
KEY
Mongodb and Totsy - E-commerce Case Study
Css1 properties
Css 3
Css 3
Scala.io
ParisJS #11 : Sass & Compass
Developing With Django
Mongodb and Totsy - E-commerce Case Study

What's hot (11)

KEY
Trendsetting: Web Design and Beyond
PDF
Mura ORM & Ember JS
PDF
Introduction 2 css
PDF
Beginning css
PDF
Back to school education powerpoint ppt slides.
PDF
Back to school education powerpoint presentation slides.
PDF
Back to school education powerpoint presentation templates.
PDF
Back to school education powerpoint ppt templates.
PPTX
Castro Chapter 7
PDF
Fuzzy search on plone & search for east asian language
PDF
Silverlight 3
Trendsetting: Web Design and Beyond
Mura ORM & Ember JS
Introduction 2 css
Beginning css
Back to school education powerpoint ppt slides.
Back to school education powerpoint presentation slides.
Back to school education powerpoint presentation templates.
Back to school education powerpoint ppt templates.
Castro Chapter 7
Fuzzy search on plone & search for east asian language
Silverlight 3
Ad

Viewers also liked (20)

PDF
Can big data reinvent the credit score?
PDF
Text Layout With Core Text
PDF
Core text
KEY
Core Text: раскрываем интерактивные возможности текста
PDF
5. Market analysis
PDF
Aasj05.02 stavrias
PPT
Uv Vis Calculated Of Mv2+ And Mv+
PDF
อธิบายเกณฑ์ด้วยแผนภาพ Criteria by diagrams
PDF
Proposta de 5 disciplinas de DADs - Desafios contemporâneos dos currículos de...
DOCX
Neural nw k means
PDF
Ke ipsos spec_poll_press_release_presentation_3rd_september_2015
PDF
Neural network-toolbox
PDF
O desafio dos Arquivistas em garantir a autenticidade e o acesso a longo praz...
PDF
Preservação de Documentos Digitais: os Repositórios Arquivísticos Digitais C...
DOC
Impacto de las normas internacionales de contabilidad en la economia colombiana
PPTX
Data frameあれこれ
PDF
A difícil tarefa de manter a Cadeia de Custódia Digital dos Documentos Arquiv...
PPT
Nic 24
PDF
SxSW Interactive 2016: In Quotes
DOCX
Entry Level International Development CV Template
Can big data reinvent the credit score?
Text Layout With Core Text
Core text
Core Text: раскрываем интерактивные возможности текста
5. Market analysis
Aasj05.02 stavrias
Uv Vis Calculated Of Mv2+ And Mv+
อธิบายเกณฑ์ด้วยแผนภาพ Criteria by diagrams
Proposta de 5 disciplinas de DADs - Desafios contemporâneos dos currículos de...
Neural nw k means
Ke ipsos spec_poll_press_release_presentation_3rd_september_2015
Neural network-toolbox
O desafio dos Arquivistas em garantir a autenticidade e o acesso a longo praz...
Preservação de Documentos Digitais: os Repositórios Arquivísticos Digitais C...
Impacto de las normas internacionales de contabilidad en la economia colombiana
Data frameあれこれ
A difícil tarefa de manter a Cadeia de Custódia Digital dos Documentos Arquiv...
Nic 24
SxSW Interactive 2016: In Quotes
Entry Level International Development CV Template
Ad

Similar to Cocoa text talk.key (20)

PDF
Intro to css & sass
KEY
Character sets
PDF
What is-sass-by-lucas-castro
PPT
Chapter 04bnbnbbnmbnmbmbmnbmnnbnmbnnm.ppt
PDF
Software Engineering Thailand: Programming with Scala
KEY
Advanced sass/compass
PPT
Creating Fixed-Layout EPUBs
PPT
Chapter 2 : TEXT
PPT
Chapter 2
PPTX
Hunting for anglerfish in datalakes
PDF
Ballerina- A programming language for the networked world
PDF
Ballerina- A programming language for the networked world
PDF
Typography and user experience - UX Craft 2014
 
PDF
Alexey Golub - Writing parsers in c# | 3Shape Meetup
PDF
Intro to html, css & sass
PPTX
Markup languages and warp-speed documentation
PDF
Lois Patterson: Markup Languages and Warp-Speed Documentation
PDF
Bshmanual
PDF
Building DSLs with Scala
Intro to css & sass
Character sets
What is-sass-by-lucas-castro
Chapter 04bnbnbbnmbnmbmbmnbmnnbnmbnnm.ppt
Software Engineering Thailand: Programming with Scala
Advanced sass/compass
Creating Fixed-Layout EPUBs
Chapter 2 : TEXT
Chapter 2
Hunting for anglerfish in datalakes
Ballerina- A programming language for the networked world
Ballerina- A programming language for the networked world
Typography and user experience - UX Craft 2014
 
Alexey Golub - Writing parsers in c# | 3Shape Meetup
Intro to html, css & sass
Markup languages and warp-speed documentation
Lois Patterson: Markup Languages and Warp-Speed Documentation
Bshmanual
Building DSLs with Scala

Cocoa text talk.key