quartz-2d
UIView with a Dashed line
Check UIBezierPath setLineDash:count:phase: method: – (void)setLineDash:(const CGFloat *)pattern count:(NSInteger)count phase:(CGFloat)phase` method. This allows you to draw dashed lines. First add a CAShapeLayer. Add it as sublayer to your UIView. It has a path property. Now make an object of UIBezierPath. Draw the line using setLineDash. For example: UIBezierPath *path = [UIBezierPath bezierPath]; //draw a line … Read more
Most efficient way to draw part of an image in iOS
I guessed you are doing this to display part of an image on the screen, because you mentioned UIImageView. And optimization problems always need defining specifically. Trust Apple for Regular UI stuff Actually, UIImageView with clipsToBounds is one of the fastest/simplest ways to archive your goal if your goal is just clipping a rectangular region … Read more
How can I draw an arrow using Core Graphics?
UPDATE I’ve posted a Swift version of this answer separately. ORIGINAL This is a fun little problem. First of all, there are lots of ways to draw arrows, with curved or straight sides. Let’s pick a very simple way and label the measurements we’ll need: We want to write a function that takes the start … Read more
Contex Drawing + Pagination
I don’t think you need the code which flips the PDF upside down. I’ve done this before (manual pagination, but without a scroll view) and never had to flip the context vertically. My main concern is that you are doing it on every iteration – if you have a valid reason for flipping it, you … Read more
Curve text on existing circle
I adapted Apple’s CoreTextArcCocoa sample project (mentioned by Tom H in this reply) and thought I’d share it here. I added a few other features as well, such as the ability to set the arc size to something smaller than 180, and the text color and offset shift as properties (so that you don’t have … Read more
What’s the difference between Quartz Core, Core Graphics and Quartz 2D?
Quartz 2D is an API of the Core Graphics framework that implements drawing. Quartz Core is a framework that includes APIs for animation and image processing. Quartz frameworks and their APIs CoreGraphics.framework Quartz 2D API manages the graphic context and implements drawing. Quartz Services API provides low level access to the window server. This includes … Read more
How to map atan2() to degrees 0-360
Solution using Modulo A simple solution that catches all cases. degrees = (degrees + 360) % 360; // +360 for implementations where mod returns negative numbers Explanation Positive: 1 to 180 If you mod any positive number between 1 and 180 by 360, you will get the exact same number you put in. Mod here … Read more