Drawing in iOS - Part 10: Introduction | Ray Wenderlich Videos

Let's review what you'll be learning in this section, and find out about the three controls you'll design.

This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4659-drawing-in-ios/lessons/10
1 Like

Hi @Caroline. First of all, this is a great course! Perfect level of detail without feeling overwhelmed!

One reason I went through this course was to better understand the difference between CALayers and core graphics, specifically around performance. It’s my understanding using CALayers and UIKit is generally preferred because of optimizations the operation system is able to do, which I believe you eluded to a couple times. One thing I’m still not clear on, though, is when to realistically have the need to use core graphics. You mentioned one reason may be when you have dynamic data, like the cupcakes and numbers on the timer, but since that data is known when rendering the view, wouldn’t CALayers work just fine? If you needed to update anything on data changes, couldn’t you just use transforms on the layers? Also, I’ve read overriding drawRect: can prevent UIKit optimizations, so seems like another reason to shy way from using core graphics.

Any :bulb:you can shine on this would be great. Thanks again for putting this together!

1 Like

@derrickshowers - Yes, you could go through life using CALayers, and they’re great. But if you’re drawing a more complex picture that would require a ton of CAShapeLayers or trying to get at the pixel level, then you’d probably want to use a Core Graphics context. If you wanted, you could then extract an image from the CGContext and use it as a layer’s contents.

My suggestion if you’re unsure, is to use CALayers until you can’t. For example, if you make a table view and draw CALayers on each cell, it won’t be as efficient as using draw(_:). Ages ago I proved that, but I’m not 100% sure it still stands in the newer iOSes.

Btw, every time you use a CGFloat or a CGPoint, you’re actually accessing the Core Graphics API.

This is my favourite thing I’ve seen recently: https://noahgilmore.com/blog/cifilter-colorwheel/ - it’s about using CIFilter for a color picker, but you still need to use a CGContext for the pixel level.

1 Like

Thanks so much @caroline for the quick response! Makes complete sense, and I also have read about how using a bunch of layers in a table view cell could cause performance issues. I guess I was just stuck on “dynamic vs static” as a decision factor in determining when to use what.

The color picker is neat! Thanks for sharing!

1 Like