SlideShare a Scribd company logo
1 of 22
Download to read offline
Boutique product development company
It is amazing what you can accomplish when you have a client-centric team to deliver outstanding products.
Advance Text Rendering In iOS
      Sohail Mohabbat Ali| iOS Mentor
Advance Text Rendering In iOS
Topics covered in the presentation




     •   Back Ground
     •   Core Text
     •   How to Do It?
     •   How to Fix IT




                                     or
                                          Sohail Mohabbat Ali | iOS Mentor
Advance text Rendering in iOS


Text Rendering in iOS


   •      UIKit

   •      Core Graphics/Quartz

   •      Core Text




                                 Sohail Mohabbat Ali | iOS Mentor
Advance text Rendering in iOS


Text Rendering in iOS Cont..

  UIKit:

  In UIKit you have             and you add a word or a text line on
  the screen by simple Drag-and-Drop in IB, but you cannot do
  many things like strikethrough and custom formatting.




                                                    Sohail Mohabbat Ali | iOS Mentor
Advance text Rendering in iOS


Text Rendering in iOS Cont..

  Core Graphics/Quartz:

  In                            you can do pretty much everything the
  system is capable of, but you need to calculate the position of each
  glyph in your text and draw it on the screen.




                                                    Sohail Mohabbat Ali | iOS Mentor
Advance text Rendering in iOS


Text Rendering in iOS Cont..

  Core Text:

                   lies right between the two! You have complete control over
  position, layout, attributes like color and size, but Core Text takes care
  of everything else for you – from word wrap to font rendering and more.




                                                       Sohail Mohabbat Ali | iOS Mentor
Advance text Rendering in iOS


Back Ground

                                      A tale of two Apples
      • The original Apple development team created “Classic” APIs
                                and

      • The NeXT team created NS* APIs which we later called
          “            ”

      • Since the merge of the two company, solutions like
          and                   were created to close the gap

      • For modern, Unicode-aware text layout, there is                          which
          is still a popular choice for now

                                                            Sohail Mohabbat Ali | iOS Mentor
Advance text Rendering in iOS


Background

                                  More about ATSUI

    • Short for “                                                        ”

                      Like API (OSErr, Fixed, Pascal String, etc.)

    • Fast, robust, powerful, but the API is bit complicate to use

                (for font enumeration and selection) still exists, but ATSUI
        is now                          , no 64-bit support




                                                        Sohail Mohabbat Ali | iOS Mentor
Advance text Rendering in iOS


Why Core Text ?


 • Simpler, Core Foundation style API, much easier to call from
      Cocoa apps

 • Minimize                     between different data formats, improve
      performance (up to 2 times faster according to Apple)

 • Supported behavior (like font traits) closely matches with
      Cocoa Text System




                                                    Sohail Mohabbat Ali | iOS Mentor
Advance text Rendering in iOS


What is easy with Core Text


 • Lay formatted text down on the screen

 • Fine tune the text’s appearance

 • Add images inside the text content

 • Display data in columns

 • Display text with different transformations




                                                 Sohail Mohabbat Ali | iOS Mentor
Advance text Rendering in iOS


How to do it ?

                                Step 1: Prepare Attributed String

       • First, you prepare a                      with all the parameters set
         (to the whole string or part of the string):

       NSAttributedString * str = [[NSAttributedString alloc]
               initWithString:@”Hello core text world!”
               attributes:[NSDictionary
               dictionaryWithObjectsAndKeys:
               [UIFont fontWithName:@"Helvetive" size:12.0],
               (NSString *) kCTFontAttributeName]];

          CFAttributedStringRef attrString =
                (CFAttributedStringRef) str;
                                                         Sohail Mohabbat Ali | iOS Mentor
Advance text Rendering in iOS


What is easy with Core Text

                                Step 2: Create a CTFramesetter
      • Now you can create a central object for Core Text typesetting:
                      , you will use it through the entire layout
        process:


      CTFramesetterRef framesetter =
      CTFramesetterCreateWithAttributedString(attrString);




                                                        Sohail Mohabbat Ali | iOS Mentor
Advance text Rendering in iOS


What is easy with Core Text


                                Step 3: Create a CGPath

         • Third, you add one or more               (or other shapes) to form
           a complete         :


             CGMutablePathRef path =
                                CGPathCreateMutable();


             CGRect bounds = self.bounds;


             CGPathAddRect(path, NULL, bounds);


                                                         Sohail Mohabbat Ali | iOS Mentor
Advance text Rendering in iOS


What is easy with Core Text


                                Step 4: Get the Frame

    Use the          and                  to create            (s), then draw it in
       current context

        CGContextRef context = UIGraphicsGetCurrentContext();

        CTFrameRef frame =
             CTFramesetterCreateFrame(framesetter,
                               CFRangeMake(0, 0),
                               path, NULL);

        CTFrameDraw(frame , context);


                                                      Sohail Mohabbat Ali | iOS Mentor
Advance text Rendering in iOS


What is easy with Core Text


                         Step 5: Don’t forget to release them

 Release everything you created with CGRelease.



  CFRelease(attrString);

  CFRelease(framesetter);

  CFRelease(frame);

  CFRelease(path);


                                                    Sohail Mohabbat Ali | iOS Mentor
Advance text Rendering in iOS


What is easy with Core Text


                         Step 5: Don’t forget to release them

 Release everything you created with CGRelease.



  CFRelease(attrString);

  CFRelease(framesetter);

  CFRelease(frame);

  CFRelease(path);


                                                    Sohail Mohabbat Ali | iOS Mentor
Advance text Rendering in iOS


How to                it ?




  CGContextSetTextMatrix(context, CGAffineTransformIdentity);


  CGContextTranslateCTM(context, 0, self.bounds.size.height);


  CGContextScaleCTM(context, 1.0, -1.0);




                                              Sohail Mohabbat Ali | iOS Mentor
Advance text Rendering in iOS


Writing on Shapes

  CGMutablePathRef path = CGPathCreateMutable();



  CTFramesetterRef framesetter =
  CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attString);

  CTFrameRef theFrame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0,
  [attString length]), path, NULL);

  CFRelease(framesetter);

  CFRelease(path);

  CTFrameDraw(theFrame, context);

  CFRelease(theFrame);
                                                        Sohail Mohabbat Ali | iOS Mentor
Advance text Rendering in iOS


Writing on Shapes (Output)




                                Sohail Mohabbat Ali | iOS Mentor
Advance text Rendering in iOS


Writing on Shapes (Output)




                                Sohail Mohabbat Ali | iOS Mentor
Advance text Rendering in iOS


Playing with NSA Tributed String


  With the help of function




  we can format different chunks
  of strings with different
  attributes




                                   Sohail Mohabbat Ali | iOS Mentor

More Related Content

What's hot

Solid And Sustainable Development in Scala
Solid And Sustainable Development in ScalaSolid And Sustainable Development in Scala
Solid And Sustainable Development in ScalaKazuhiro Sera
 
Declarative UI on iOS without SwiftUI (中文)
Declarative UI on iOS without SwiftUI (中文)Declarative UI on iOS without SwiftUI (中文)
Declarative UI on iOS without SwiftUI (中文)Shih-Ting Huang
 
Node.js vs Play Framework (with Japanese subtitles)
Node.js vs Play Framework (with Japanese subtitles)Node.js vs Play Framework (with Japanese subtitles)
Node.js vs Play Framework (with Japanese subtitles)Yevgeniy Brikman
 
Introduction to node.js by Ran Mizrahi @ Reversim Summit
Introduction to node.js by Ran Mizrahi @ Reversim SummitIntroduction to node.js by Ran Mizrahi @ Reversim Summit
Introduction to node.js by Ran Mizrahi @ Reversim SummitRan Mizrahi
 
Seven Versions of One Web Application
Seven Versions of One Web ApplicationSeven Versions of One Web Application
Seven Versions of One Web ApplicationYakov Fain
 
Sling Models Using Sightly and JSP by Deepak Khetawat
Sling Models Using Sightly and JSP by Deepak KhetawatSling Models Using Sightly and JSP by Deepak Khetawat
Sling Models Using Sightly and JSP by Deepak KhetawatAEM HUB
 
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)Stephen Chin
 
Mastering the Sling Rewriter
Mastering the Sling RewriterMastering the Sling Rewriter
Mastering the Sling RewriterJustin Edelson
 
Intro to JavaScript Testing
Intro to JavaScript TestingIntro to JavaScript Testing
Intro to JavaScript TestingRan Mizrahi
 
The Grid the Brad and the Ugly: Using Grids to Improve Your Applications
The Grid the Brad and the Ugly: Using Grids to Improve Your ApplicationsThe Grid the Brad and the Ugly: Using Grids to Improve Your Applications
The Grid the Brad and the Ugly: Using Grids to Improve Your Applicationsbalassaitis
 
SenchaCon 2016: How to Auto Generate a Back-end in Minutes - Per Minborg, Emi...
SenchaCon 2016: How to Auto Generate a Back-end in Minutes - Per Minborg, Emi...SenchaCon 2016: How to Auto Generate a Back-end in Minutes - Per Minborg, Emi...
SenchaCon 2016: How to Auto Generate a Back-end in Minutes - Per Minborg, Emi...Sencha
 
Object Oriented Programing in JavaScript
Object Oriented Programing in JavaScriptObject Oriented Programing in JavaScript
Object Oriented Programing in JavaScriptAkshay Mathur
 
Scalable JavaScript Design Patterns
Scalable JavaScript Design PatternsScalable JavaScript Design Patterns
Scalable JavaScript Design PatternsAddy Osmani
 
Building Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaBuilding Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaWO Community
 
Medium TechTalk — iOS
Medium TechTalk — iOSMedium TechTalk — iOS
Medium TechTalk — iOSjimmyatmedium
 
The Theory Of The Dom
The Theory Of The DomThe Theory Of The Dom
The Theory Of The Domkaven yan
 

What's hot (20)

Solid And Sustainable Development in Scala
Solid And Sustainable Development in ScalaSolid And Sustainable Development in Scala
Solid And Sustainable Development in Scala
 
Declarative UI on iOS without SwiftUI (中文)
Declarative UI on iOS without SwiftUI (中文)Declarative UI on iOS without SwiftUI (中文)
Declarative UI on iOS without SwiftUI (中文)
 
Node.js vs Play Framework (with Japanese subtitles)
Node.js vs Play Framework (with Japanese subtitles)Node.js vs Play Framework (with Japanese subtitles)
Node.js vs Play Framework (with Japanese subtitles)
 
Introduction to node.js by Ran Mizrahi @ Reversim Summit
Introduction to node.js by Ran Mizrahi @ Reversim SummitIntroduction to node.js by Ran Mizrahi @ Reversim Summit
Introduction to node.js by Ran Mizrahi @ Reversim Summit
 
Seven Versions of One Web Application
Seven Versions of One Web ApplicationSeven Versions of One Web Application
Seven Versions of One Web Application
 
Sling Models Using Sightly and JSP by Deepak Khetawat
Sling Models Using Sightly and JSP by Deepak KhetawatSling Models Using Sightly and JSP by Deepak Khetawat
Sling Models Using Sightly and JSP by Deepak Khetawat
 
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)
JavaFX 2 and Scala - Like Milk and Cookies (33rd Degrees)
 
Advance JS and oop
Advance JS and oopAdvance JS and oop
Advance JS and oop
 
Mastering the Sling Rewriter
Mastering the Sling RewriterMastering the Sling Rewriter
Mastering the Sling Rewriter
 
Intro to JavaScript Testing
Intro to JavaScript TestingIntro to JavaScript Testing
Intro to JavaScript Testing
 
The Grid the Brad and the Ugly: Using Grids to Improve Your Applications
The Grid the Brad and the Ugly: Using Grids to Improve Your ApplicationsThe Grid the Brad and the Ugly: Using Grids to Improve Your Applications
The Grid the Brad and the Ugly: Using Grids to Improve Your Applications
 
SenchaCon 2016: How to Auto Generate a Back-end in Minutes - Per Minborg, Emi...
SenchaCon 2016: How to Auto Generate a Back-end in Minutes - Per Minborg, Emi...SenchaCon 2016: How to Auto Generate a Back-end in Minutes - Per Minborg, Emi...
SenchaCon 2016: How to Auto Generate a Back-end in Minutes - Per Minborg, Emi...
 
Real World MVC
Real World MVCReal World MVC
Real World MVC
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Object Oriented Programing in JavaScript
Object Oriented Programing in JavaScriptObject Oriented Programing in JavaScript
Object Oriented Programing in JavaScript
 
jQuery Objects
jQuery ObjectsjQuery Objects
jQuery Objects
 
Scalable JavaScript Design Patterns
Scalable JavaScript Design PatternsScalable JavaScript Design Patterns
Scalable JavaScript Design Patterns
 
Building Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with ScalaBuilding Concurrent WebObjects applications with Scala
Building Concurrent WebObjects applications with Scala
 
Medium TechTalk — iOS
Medium TechTalk — iOSMedium TechTalk — iOS
Medium TechTalk — iOS
 
The Theory Of The Dom
The Theory Of The DomThe Theory Of The Dom
The Theory Of The Dom
 

Similar to Boutique product dev company

Introducing ios core ml
Introducing ios core mlIntroducing ios core ml
Introducing ios core mlAbby Lai
 
Programming iOS in C#
Programming iOS in C#Programming iOS in C#
Programming iOS in C#Frank Krueger
 
Best Apple IOS Training in Chennai | Best Iphone Training in Chennai
Best Apple IOS Training in Chennai | Best Iphone Training in ChennaiBest Apple IOS Training in Chennai | Best Iphone Training in Chennai
Best Apple IOS Training in Chennai | Best Iphone Training in ChennaiCore Mind
 
Layer architecture of ios (1)
Layer architecture of ios (1)Layer architecture of ios (1)
Layer architecture of ios (1)dwipalp
 
[CocoaHeads Tricity] Do not reinvent the wheel
[CocoaHeads Tricity] Do not reinvent the wheel[CocoaHeads Tricity] Do not reinvent the wheel
[CocoaHeads Tricity] Do not reinvent the wheelMateusz Klimczak
 
Enhance the Look of Your App With Text Kit
Enhance the Look of Your App With Text KitEnhance the Look of Your App With Text Kit
Enhance the Look of Your App With Text KitMatteo Battaglio
 
iOS Development - Offline Class for Jasakomer
iOS Development - Offline Class for JasakomeriOS Development - Offline Class for Jasakomer
iOS Development - Offline Class for JasakomerAndri Yadi
 
iOS Development Survival Guide for the .NET Guy
iOS Development Survival Guide for the .NET GuyiOS Development Survival Guide for the .NET Guy
iOS Development Survival Guide for the .NET GuyNick Landry
 
Understanding iOS from an Android perspective
Understanding iOS from an Android perspectiveUnderstanding iOS from an Android perspective
Understanding iOS from an Android perspectiveLauren Yew
 
Compose Camp Day 3 PPT.pptx.pdf
Compose Camp Day 3 PPT.pptx.pdfCompose Camp Day 3 PPT.pptx.pdf
Compose Camp Day 3 PPT.pptx.pdfMETDSC
 
Down With JavaScript!
Down With JavaScript!Down With JavaScript!
Down With JavaScript!Garth Gilmour
 
How to add Custom Font to your iOS-based App?
How to add Custom Font to your iOS-based App?How to add Custom Font to your iOS-based App?
How to add Custom Font to your iOS-based App?Neev Technologies
 
Getting started with titanium
Getting started with titaniumGetting started with titanium
Getting started with titaniumNaga Harish M
 
Getting started with Appcelerator Titanium
Getting started with Appcelerator TitaniumGetting started with Appcelerator Titanium
Getting started with Appcelerator TitaniumTechday7
 
The iOS technical interview: get your dream job as an iOS developer
The iOS technical interview: get your dream job as an iOS developerThe iOS technical interview: get your dream job as an iOS developer
The iOS technical interview: get your dream job as an iOS developerJuan C Catalan
 
Deep Learning in iOS Tutorial
Deep Learning in iOS TutorialDeep Learning in iOS Tutorial
Deep Learning in iOS TutorialAnyline
 
Real-world Dojo Mobile
Real-world Dojo MobileReal-world Dojo Mobile
Real-world Dojo MobileAndrew Ferrier
 
Introduction to MonoTouch
Introduction to MonoTouchIntroduction to MonoTouch
Introduction to MonoTouchJonas Follesø
 

Similar to Boutique product dev company (20)

Introducing ios core ml
Introducing ios core mlIntroducing ios core ml
Introducing ios core ml
 
Programming iOS in C#
Programming iOS in C#Programming iOS in C#
Programming iOS in C#
 
Best Apple IOS Training in Chennai | Best Iphone Training in Chennai
Best Apple IOS Training in Chennai | Best Iphone Training in ChennaiBest Apple IOS Training in Chennai | Best Iphone Training in Chennai
Best Apple IOS Training in Chennai | Best Iphone Training in Chennai
 
Layer architecture of ios (1)
Layer architecture of ios (1)Layer architecture of ios (1)
Layer architecture of ios (1)
 
[CocoaHeads Tricity] Do not reinvent the wheel
[CocoaHeads Tricity] Do not reinvent the wheel[CocoaHeads Tricity] Do not reinvent the wheel
[CocoaHeads Tricity] Do not reinvent the wheel
 
Enhance the Look of Your App With Text Kit
Enhance the Look of Your App With Text KitEnhance the Look of Your App With Text Kit
Enhance the Look of Your App With Text Kit
 
iOS Development - Offline Class for Jasakomer
iOS Development - Offline Class for JasakomeriOS Development - Offline Class for Jasakomer
iOS Development - Offline Class for Jasakomer
 
iOS Development Survival Guide for the .NET Guy
iOS Development Survival Guide for the .NET GuyiOS Development Survival Guide for the .NET Guy
iOS Development Survival Guide for the .NET Guy
 
Final ppt
Final pptFinal ppt
Final ppt
 
Understanding iOS from an Android perspective
Understanding iOS from an Android perspectiveUnderstanding iOS from an Android perspective
Understanding iOS from an Android perspective
 
Compose Camp Day 3 PPT.pptx.pdf
Compose Camp Day 3 PPT.pptx.pdfCompose Camp Day 3 PPT.pptx.pdf
Compose Camp Day 3 PPT.pptx.pdf
 
Down With JavaScript!
Down With JavaScript!Down With JavaScript!
Down With JavaScript!
 
How to add Custom Font to your iOS-based App?
How to add Custom Font to your iOS-based App?How to add Custom Font to your iOS-based App?
How to add Custom Font to your iOS-based App?
 
Getting started with titanium
Getting started with titaniumGetting started with titanium
Getting started with titanium
 
Getting started with Appcelerator Titanium
Getting started with Appcelerator TitaniumGetting started with Appcelerator Titanium
Getting started with Appcelerator Titanium
 
The iOS technical interview: get your dream job as an iOS developer
The iOS technical interview: get your dream job as an iOS developerThe iOS technical interview: get your dream job as an iOS developer
The iOS technical interview: get your dream job as an iOS developer
 
Deep Learning in iOS Tutorial
Deep Learning in iOS TutorialDeep Learning in iOS Tutorial
Deep Learning in iOS Tutorial
 
Real-world Dojo Mobile
Real-world Dojo MobileReal-world Dojo Mobile
Real-world Dojo Mobile
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Introduction to MonoTouch
Introduction to MonoTouchIntroduction to MonoTouch
Introduction to MonoTouch
 

More from Confiz

Agile training workshop
Agile training workshopAgile training workshop
Agile training workshopConfiz
 
Web services with laravel
Web services with laravelWeb services with laravel
Web services with laravelConfiz
 
DMAIC-Six sigma process Improvement Approach
DMAIC-Six sigma process Improvement ApproachDMAIC-Six sigma process Improvement Approach
DMAIC-Six sigma process Improvement ApproachConfiz
 
What is UFT? HP's unified functional testing.
What is UFT? HP's unified functional testing.What is UFT? HP's unified functional testing.
What is UFT? HP's unified functional testing.Confiz
 
Software testing methods, levels and types
Software testing methods, levels and typesSoftware testing methods, levels and types
Software testing methods, levels and typesConfiz
 
Sqa, test scenarios and test cases
Sqa, test scenarios and test casesSqa, test scenarios and test cases
Sqa, test scenarios and test casesConfiz
 
Solid principles of oo design
Solid principles of oo designSolid principles of oo design
Solid principles of oo designConfiz
 
Entity framework code first
Entity framework code firstEntity framework code first
Entity framework code firstConfiz
 
Security testing presentation
Security testing presentationSecurity testing presentation
Security testing presentationConfiz
 
Ts seo t ech session
Ts   seo t ech sessionTs   seo t ech session
Ts seo t ech sessionConfiz
 
Learning as a creative professional
Learning as a creative professionalLearning as a creative professional
Learning as a creative professionalConfiz
 
Learning as a creative professional
Learning as a creative professionalLearning as a creative professional
Learning as a creative professionalConfiz
 
Ts archiving
Ts   archivingTs   archiving
Ts archivingConfiz
 
Ts threading
Ts   threadingTs   threading
Ts threadingConfiz
 
Ts android supporting multiple screen
Ts   android supporting multiple screenTs   android supporting multiple screen
Ts android supporting multiple screenConfiz
 
Ts drupal6 module development v0.2
Ts   drupal6 module development v0.2Ts   drupal6 module development v0.2
Ts drupal6 module development v0.2Confiz
 
Photoshop manners
Photoshop mannersPhotoshop manners
Photoshop mannersConfiz
 
Monkey talk
Monkey talkMonkey talk
Monkey talkConfiz
 
An insight to microsoft platform
An insight to microsoft platformAn insight to microsoft platform
An insight to microsoft platformConfiz
 
Ts branching over the top
Ts   branching over the topTs   branching over the top
Ts branching over the topConfiz
 

More from Confiz (20)

Agile training workshop
Agile training workshopAgile training workshop
Agile training workshop
 
Web services with laravel
Web services with laravelWeb services with laravel
Web services with laravel
 
DMAIC-Six sigma process Improvement Approach
DMAIC-Six sigma process Improvement ApproachDMAIC-Six sigma process Improvement Approach
DMAIC-Six sigma process Improvement Approach
 
What is UFT? HP's unified functional testing.
What is UFT? HP's unified functional testing.What is UFT? HP's unified functional testing.
What is UFT? HP's unified functional testing.
 
Software testing methods, levels and types
Software testing methods, levels and typesSoftware testing methods, levels and types
Software testing methods, levels and types
 
Sqa, test scenarios and test cases
Sqa, test scenarios and test casesSqa, test scenarios and test cases
Sqa, test scenarios and test cases
 
Solid principles of oo design
Solid principles of oo designSolid principles of oo design
Solid principles of oo design
 
Entity framework code first
Entity framework code firstEntity framework code first
Entity framework code first
 
Security testing presentation
Security testing presentationSecurity testing presentation
Security testing presentation
 
Ts seo t ech session
Ts   seo t ech sessionTs   seo t ech session
Ts seo t ech session
 
Learning as a creative professional
Learning as a creative professionalLearning as a creative professional
Learning as a creative professional
 
Learning as a creative professional
Learning as a creative professionalLearning as a creative professional
Learning as a creative professional
 
Ts archiving
Ts   archivingTs   archiving
Ts archiving
 
Ts threading
Ts   threadingTs   threading
Ts threading
 
Ts android supporting multiple screen
Ts   android supporting multiple screenTs   android supporting multiple screen
Ts android supporting multiple screen
 
Ts drupal6 module development v0.2
Ts   drupal6 module development v0.2Ts   drupal6 module development v0.2
Ts drupal6 module development v0.2
 
Photoshop manners
Photoshop mannersPhotoshop manners
Photoshop manners
 
Monkey talk
Monkey talkMonkey talk
Monkey talk
 
An insight to microsoft platform
An insight to microsoft platformAn insight to microsoft platform
An insight to microsoft platform
 
Ts branching over the top
Ts   branching over the topTs   branching over the top
Ts branching over the top
 

Boutique product dev company

  • 1. Boutique product development company It is amazing what you can accomplish when you have a client-centric team to deliver outstanding products.
  • 2. Advance Text Rendering In iOS Sohail Mohabbat Ali| iOS Mentor
  • 3. Advance Text Rendering In iOS Topics covered in the presentation • Back Ground • Core Text • How to Do It? • How to Fix IT or Sohail Mohabbat Ali | iOS Mentor
  • 4. Advance text Rendering in iOS Text Rendering in iOS • UIKit • Core Graphics/Quartz • Core Text Sohail Mohabbat Ali | iOS Mentor
  • 5. Advance text Rendering in iOS Text Rendering in iOS Cont.. UIKit: In UIKit you have and you add a word or a text line on the screen by simple Drag-and-Drop in IB, but you cannot do many things like strikethrough and custom formatting. Sohail Mohabbat Ali | iOS Mentor
  • 6. Advance text Rendering in iOS Text Rendering in iOS Cont.. Core Graphics/Quartz: In you can do pretty much everything the system is capable of, but you need to calculate the position of each glyph in your text and draw it on the screen. Sohail Mohabbat Ali | iOS Mentor
  • 7. Advance text Rendering in iOS Text Rendering in iOS Cont.. Core Text: lies right between the two! You have complete control over position, layout, attributes like color and size, but Core Text takes care of everything else for you – from word wrap to font rendering and more. Sohail Mohabbat Ali | iOS Mentor
  • 8. Advance text Rendering in iOS Back Ground A tale of two Apples • The original Apple development team created “Classic” APIs and • The NeXT team created NS* APIs which we later called “ ” • Since the merge of the two company, solutions like and were created to close the gap • For modern, Unicode-aware text layout, there is which is still a popular choice for now Sohail Mohabbat Ali | iOS Mentor
  • 9. Advance text Rendering in iOS Background More about ATSUI • Short for “ ” Like API (OSErr, Fixed, Pascal String, etc.) • Fast, robust, powerful, but the API is bit complicate to use (for font enumeration and selection) still exists, but ATSUI is now , no 64-bit support Sohail Mohabbat Ali | iOS Mentor
  • 10. Advance text Rendering in iOS Why Core Text ? • Simpler, Core Foundation style API, much easier to call from Cocoa apps • Minimize between different data formats, improve performance (up to 2 times faster according to Apple) • Supported behavior (like font traits) closely matches with Cocoa Text System Sohail Mohabbat Ali | iOS Mentor
  • 11. Advance text Rendering in iOS What is easy with Core Text • Lay formatted text down on the screen • Fine tune the text’s appearance • Add images inside the text content • Display data in columns • Display text with different transformations Sohail Mohabbat Ali | iOS Mentor
  • 12. Advance text Rendering in iOS How to do it ? Step 1: Prepare Attributed String • First, you prepare a with all the parameters set (to the whole string or part of the string): NSAttributedString * str = [[NSAttributedString alloc] initWithString:@”Hello core text world!” attributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIFont fontWithName:@"Helvetive" size:12.0], (NSString *) kCTFontAttributeName]]; CFAttributedStringRef attrString = (CFAttributedStringRef) str; Sohail Mohabbat Ali | iOS Mentor
  • 13. Advance text Rendering in iOS What is easy with Core Text Step 2: Create a CTFramesetter • Now you can create a central object for Core Text typesetting: , you will use it through the entire layout process: CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(attrString); Sohail Mohabbat Ali | iOS Mentor
  • 14. Advance text Rendering in iOS What is easy with Core Text Step 3: Create a CGPath • Third, you add one or more (or other shapes) to form a complete : CGMutablePathRef path = CGPathCreateMutable(); CGRect bounds = self.bounds; CGPathAddRect(path, NULL, bounds); Sohail Mohabbat Ali | iOS Mentor
  • 15. Advance text Rendering in iOS What is easy with Core Text Step 4: Get the Frame Use the and to create (s), then draw it in current context CGContextRef context = UIGraphicsGetCurrentContext(); CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, 0), path, NULL); CTFrameDraw(frame , context); Sohail Mohabbat Ali | iOS Mentor
  • 16. Advance text Rendering in iOS What is easy with Core Text Step 5: Don’t forget to release them Release everything you created with CGRelease. CFRelease(attrString); CFRelease(framesetter); CFRelease(frame); CFRelease(path); Sohail Mohabbat Ali | iOS Mentor
  • 17. Advance text Rendering in iOS What is easy with Core Text Step 5: Don’t forget to release them Release everything you created with CGRelease. CFRelease(attrString); CFRelease(framesetter); CFRelease(frame); CFRelease(path); Sohail Mohabbat Ali | iOS Mentor
  • 18. Advance text Rendering in iOS How to it ? CGContextSetTextMatrix(context, CGAffineTransformIdentity); CGContextTranslateCTM(context, 0, self.bounds.size.height); CGContextScaleCTM(context, 1.0, -1.0); Sohail Mohabbat Ali | iOS Mentor
  • 19. Advance text Rendering in iOS Writing on Shapes CGMutablePathRef path = CGPathCreateMutable(); CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attString); CTFrameRef theFrame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, [attString length]), path, NULL); CFRelease(framesetter); CFRelease(path); CTFrameDraw(theFrame, context); CFRelease(theFrame); Sohail Mohabbat Ali | iOS Mentor
  • 20. Advance text Rendering in iOS Writing on Shapes (Output) Sohail Mohabbat Ali | iOS Mentor
  • 21. Advance text Rendering in iOS Writing on Shapes (Output) Sohail Mohabbat Ali | iOS Mentor
  • 22. Advance text Rendering in iOS Playing with NSA Tributed String With the help of function we can format different chunks of strings with different attributes Sohail Mohabbat Ali | iOS Mentor