Skip to content

INTERNALS: View Composition

klazuka edited this page Sep 13, 2010 · 1 revision

Each square in the currently display month is represented by a KalTileView object. This object is responsible for drawing the day number, drawing the dot marker when there is associated application data for that date, and drawing a highlight when selected. The actual grid lines between each tile are drawn by KalMonthView.

One interesting thing about KalTileView is that it does not use any subviews to draw the text, marker image, or highlight. Instead, everything is drawn directly in -[KalTileView drawRect:]. I decided to do things this way because profiling revealed that the slide animation’s framerate was very bad when KalTileView implemented its drawing as a composition of its subview hierarchy (e.g. a UILabel and two UIImageViews). By drawing everything in a single drawRect:, the framerate was substantially improved.

For more details, see this discussion on the Atebits blog.