Drawing A Chess Board in iOS   Jan 29, 2014

I've been working on a new iOS app which is a chess game and I needed a way to draw a chess board of various sizes. In this brief post I discuss how I use Core Graphics to draw the game board at a given size.


Why use Core Graphics and not just static images?

So you might ask why I'd bother drawing the board in Core Graphics instead of just including a nice bitmap image for either the whole board or for individual squares that could be repeated. I've listed the main reasons below

  • I need to cater for devices with different resolutions and therefore manage many different images
  • I didn't want to bloat my application's download size unnecessarily with image files
  • Rendering of UITableViewCells should be faster using Core Graphics than it would be with static images

The Code

The code below is pretty self-explanatory I think, but you can check it out on GitHub and clone the repo or suggest improvements to my efforts

Screenshot

Here is a screenshot of the board including the chess pieces placed on it. You can see the nice gradient effect

Chess Board drawn with iOS Core Graphics

Tags for this post:

 Back