This document provides an introduction to using QuartzCore and CoreText to build high-performance table views on iOS. It begins by explaining why fast scrolling is important for the iPhone experience. It then outlines three different methods for compositing table view cells (subviews, direct drawing, hybrid) and their pros and cons. The document dives into using QuartzCore and CoreText to render text and images within table view cells, providing examples of using CALayers, CATextLayers, and NSAttributedStrings. It concludes with performance tips for working with these frameworks like using dispatch_once.
Hi performance table views with QuartzCore and CoreText
1. Hi-Performance Table
Views with QuartzCore
and CoreText
Beginners guide to an advanced concept
Mugunth Kumar
Steinlogic Consulting and Training Pte Ltd
3. About me
• Author of the iOS 5, iOS 6 Programming:
Pushing the Limits book - Reached the top
100 books in Amazon’s Computer and
Technology books list
• Trainer - Conducts training on iOS
programming at iOSTraining.sg.
• Developer
• MKNetworkKit (1200+ watchers)
• MKStoreKit (700+ watchers)
• Several other “minor” projects with 200+
watchers
• Clients include startups in Singapore like
Squiryl, Found and MNC’s including
Microsoft Redmond, Oracle and such.
4. Why?
• What makes apps pleasant to use?
• Fast scrolling
• Why?
7. Why?
• iPhone is a direct manipulation device
• iPhone screen is closer to your eye than your HDTV or your
computer monitor
8. Why?
• iPhone is a direct manipulation device
• iPhone screen is closer to your eye than your HDTV or your
computer monitor
• 60 frames per second = 16.66ms per frame
9. Why?
• iPhone is a direct manipulation device
• iPhone screen is closer to your eye than your HDTV or your
computer monitor
• 60 frames per second = 16.66ms per frame
• Anything less, you will get a headache
13. Agenda
• Why?
• Three different methods
• Pros and Cons
14. Agenda
• Why?
• Three different methods
• Pros and Cons
• QuartzCore/CoreText introduction
15. Agenda
• Why?
• Three different methods
• Pros and Cons
• QuartzCore/CoreText introduction
• A simple table view cell example
16. Agenda
• Why?
• Three different methods
• Pros and Cons
• QuartzCore/CoreText introduction
• A simple table view cell example
• What else can you build? - Facebook style news feed
19. Pros/Cons
• Advantages
• Programmatically easy
• Fast for compositing images
• Built in cells are rendered differently
20. Pros/Cons
• Advantages
• Programmatically easy
• Fast for compositing images
• Built in cells are rendered differently
• Drawbacks
• Slow for text based tables
29. Cons
• Still cannot render shadows around images views
self.view.layer.masksToBounds = NO;
self.view.layer.shadowColor = [UIColor blackColor].CGColor;
self.view.layer.shadowOffset = CGSizeMake(0.0f, -1.0f);
self.view.layer.shadowOpacity = 0.5f;
self.view.layer.shadowRadius = 1.0f;
• The above code is dog slow.
• Good for views, very bad for table view cells or collection view
cells
30. Is there a better way?
• QuartzCore.framework
• CoreText.framework
32. Pros/Cons
• Advantages
• Fast
• Can render text and image within our 16ms deadline
• Rendering highly customized text is hard
33. Pros/Cons
• Advantages
• Fast
• Can render text and image within our 16ms deadline
• Rendering highly customized text is hard
This is BOLD and this is in italics.
57. What else available?
• And that is just text.
• Lot more for image rendering
• Even lot more for animation
• NSLinkAttributeName not available on iOS. You should look
at OHAttributedLabel or play around with UIButtons
60. Performance tips
• Use dispatch_once for almost any “constants”
• UIFont, UIBezierPath, UIColor etc.,
61. Performance tips
• Use dispatch_once for almost any “constants”
• UIFont, UIBezierPath, UIColor etc.,
62. Performance tips
• Use dispatch_once for almost any “constants”
• UIFont, UIBezierPath, UIColor etc.,
• Use strptime* methods instead of NSDateFormatter
• No support for locale, but crazy fast
63. Thanks
@mugunthkumar
mugunth@steinlogic.com
iostraining.sg
Available for consulting
services
iOS App Development
API Design
Mobile UX