Questions tagged [cgcontext]

The CGContextRef opaque type represents a Quartz 2D drawing destination.

977 questions
17
votes
4 answers

When drawing an arc using CGContextAddArcToPoint(), what does (x1,y1) and (x2,y2) mean?

You can use the following code to draw an arc using Quartz: CGContextMoveToPoint(context2, x, y); CGContextAddArcToPoint(context2, x1, y1, x2, y2, r); In these functions, (x,y) is the starting point and r is the arc radius but what are (x1,y1) and…
Vineesh TP
  • 7,755
  • 12
  • 66
  • 130
17
votes
8 answers

How to draw heart shape in UIView (iOS)?

I want to create different shapes. Below image is the one of example. Will you suggest me how to different shapes?
Rajesh Maurya
  • 3,026
  • 4
  • 19
  • 37
17
votes
3 answers

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…
iphaaw
  • 6,764
  • 11
  • 58
  • 83
17
votes
2 answers

Reusing a CGContext causing odd performance losses

My class is rendering images offscreen. I thought reusing the CGContext instead of creating the same context again and again for every image would be a good thing. I set a member variable _imageContext so I would only have to create a new context if…
Enie
  • 649
  • 5
  • 18
16
votes
3 answers

Swift on OS X: How to access the current CGContext for drawing in -[NSView drawRect:]

Setup: Xcode 6.1 OS X 10.9.5 Swift Mac Document-based Application target Question: I am using Swift to make a Cocoa Mac app (NOT iOS!). I have a custom NSView subclass. I'd like to override -drawRect:, and access the current CGContext to do some…
Todd Ditchendorf
  • 11,217
  • 14
  • 69
  • 123
16
votes
1 answer

CALayer renderInContext: Position of Drawing

I have a UIView with a custom shape drawn in drawRect:. The frame property is set to: {5.f, 6.f, 50.f, 50.f} Now, I render the view in an Image Context, but it is ignoring the frame property of the UIView, and always drawing the UIView in the top…
Mazyod
  • 22,319
  • 10
  • 92
  • 157
15
votes
3 answers

How to fill a UIView with an alternating stripe pattern programmatically using Swift?

I can achieve an alternating stripe pattern fill using an image with UIColor(patternImage: UIImage(named: "pattern.png")). However, how can I achieve an alternating stripe pattern fill drawing it programmatically with some simple compact code? Here…
user4806509
  • 2,925
  • 5
  • 37
  • 72
15
votes
4 answers

Rotate image using CGContextDrawImage

How can I rotate an image drawn by CGContextDrawImage() at its center? In drawRect: CGContextSaveGState(c); rect = CGRectOffset(rect, -rect.size.width / 2, -rect.size.height / 2); CGContextRotateCTM(c, angle); CGContextDrawImage(c, rect,…
14
votes
1 answer

CALayer vs CGContext, which is a better design approach?

I have been doing some experimenting with iOS drawing. To do a practical exercise I wrote a BarChart component. The following is the class diagram (well, I wasnt allowed to upload images) so let me write it in words. I have a NGBarChartView which…
Murali Raghuram
  • 255
  • 2
  • 8
14
votes
4 answers

Line graphs on iOS

Anyone know how to create line graphs on iOS without using Core-Plot but using inbuilt frameworks? Desperately searching for an answer.
Joel Joseph
  • 192
  • 1
  • 1
  • 9
14
votes
8 answers

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: -…
Tom Irving
  • 10,041
  • 6
  • 47
  • 63
13
votes
4 answers

Drawing triangle/arrow on a line with CGContext

I am using the framework of route-me for working with locations. In this code the path between two markers(points) will be drawn as a line. My Question: "What code should I add if I want to add an arrow in the middle(or top) of the line, so that it…
Pete
  • 173
  • 1
  • 1
  • 9
13
votes
4 answers

iOS to Mac GraphicContext Explanation/Conversion

I have been programming for two years on iOS and never on mac. I am working on a little utility for handling some simple image needs that I have in my iOS development. Anyway, I have working code in iOS that runs perfectly but I have absolutely no…
daveMac
  • 3,041
  • 3
  • 34
  • 59
12
votes
3 answers

Drawing Hollow circle in iPhone

i need to draw the following image The Gray part is what i want to draw over another image what is the Code i need to use using CGContext methods, i tried using the CGContextAddArc but failed because when i fill the stroke the center hollow is also…
RVN
  • 4,157
  • 5
  • 32
  • 35
12
votes
3 answers

Draw Line using CGContext

I want to draw line in table view cell so that I can place textfield & switch in single cell. I increased the height of cell. How can I draw line in cell? I have subclass of UIView which contains following code //Get the CGContext from this view …
iOSAppDev
  • 2,755
  • 4
  • 39
  • 77
1
2
3
65 66