Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 9: Creating Custom Cells with Su... > Drawing Cells in Code with layoutSub...

Drawing Cells in Code with layoutSubviews

Laying out cells visually will take you so far, but if you prefer a code-based approach you can override the layoutSubviews method in the custom cell subclass, which allows you to tweak the standard UITableViewCell styles.

Overriding the layoutSubviews Method

The layoutSubviews method is called on the cell just before it's displayed – it's a last opportunity to tweak the layout and look of the cell before it's drawn.

If the contents of your cell can be fitted into one of the standard cell types, but you just want to move things around a bit, then overriding the layoutSubviews might be the quick fix you're after – the example below shows how you might move the textLabel and the detailTextLabel around to create a new cell style, but still exploit some of the standard elements.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint