Tag: cgcontext

How to erase finger paint on Custom UIView in iPhone

I have created a custom UIView (without .xib) for a finger paint application. Paint is working fine with custom UIView but my problem is that when I try to erase the painted path I am getting: Error : Invalid context Below is my class: .h file @interface draw2D : UIView { CGPoint previousPoint; CGPoint lastPoint; […]

Using CGContext to display a sprite sheet iPhone

So I have a spritesheet in png format, and have already worked out the coordinates for what I want to display. I’m trying to create a method that will return a UIImage when passed the location information on the spritesheet. I’m just not sure how to use the CGContext stuff along with the the coordinates […]

Create new UIImage by adding shadow to existing UIImage

I’ve taken a look at this question: UIImage Shadow Trouble But the accepted answer didn’t work for me. What I’m trying to do is take a UIImage and add a shadow to it, then return a whole new UIImage, shadow and all. This is what I’m trying: – (UIImage*)imageWithShadow { CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB(); CGContextRef […]

How can I use Core Graphics to draw a circle at my touch location?

New programmer here. I am having issues trying to use Core Graphics to draw a stroked arc around my touch location. I have the method to draw the circle working fine, and I have tested and am registering touches when I tap the screen, but when I try to call the method to draw the […]

How to get rid of this “points” between my lines when I am drawing?

is there an easy way to not draw this points in my lines? I don’t know why this points are there because i never release my finger from screen during drawing of a line. I got the code from a drawing example. // draw a line – (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { mouseSwiped = YES; […]

iphone MPMoviePlayerViewController CGContext Errors

I am writing an app for the iPhone that will play some movies utilizing MPMoviePlayerViewController. So far I have gotten it to play movies, however it is throwing some errors in the debugger that all start with CGContext. I have wracked my brain in trying to fix it. Here are the details of my code: […]

How to draw a line between two points over an image in swift 3?

I am new to swift, I want to draw a line between 2 points over an image which I called mapView, I tried to use CGContext but got no result, any idea to help? Thanks. UIGraphicsBeginImageContext(mapView.bounds.size) let context : CGContext = UIGraphicsGetCurrentContext()! context.addLines(between: [CGPoint(x:oldX,y:oldY), CGPoint(x:newX, y:newY)]) context.setStrokeColorSpace(CGColorSpaceCreateDeviceRGB()) context.setStrokeColor(UIColor.blue.cgColor.components!) context.setLineWidth(3) mapView?.image?.draw(at: CGPoint(x:0, y:0)) context.strokePath() mapView.image = […]

How to procedurally draw rectangle / lines in swift using CGContext

I’ve been trawling the internet for days trying to find the simplest code examples on how to draw a rectangle or lines procedurally in Swift. I have seen how to do it by overriding the DrawRect command. I believe you can create a CGContext and then drawing into an image, but I’d love to see […]

How to draw a UILabel with a different blend mode in draw(_ rect: CGRect) in Swift

So I have a UILabel that is being drawn on top of a gradient image (that is a UIImageView). It looks sorta like this: I’m trying to change the blendMode of the graphics context in the UILabel‘s draw(_ rect: CGRect) function so that it draws the label but blended with the background with a softLight […]

Draw a circular segment progress in SWIFT

I would like to create a circular progress with slices where each slice is an arc. I based my code on this answer: Draw segments from a circle or donut But I don’t know how to copy it and rotate it 10 times. And I would like to color it following a progress variable (in […]