Questions tagged [drawrect]

Method in UIView/NSView class. Draws the receiver’s image within the passed-in rectangle.

Signature

- (void)drawRect:(CGRect)rect

rect - The portion of the view’s bounds that needs to be updated. The first time your view is drawn, this rectangle is typically the entire visible bounds of your view. However, during subsequent drawing operations, the rectangle may specify only part of your view.

The default implementation of this method does nothing. Subclasses that use native drawing technologies (such as Core Graphics and UIKit) to draw their view’s content should override this method and implement their drawing code there.

1051 questions
2
votes
3 answers

Is drawRect ---- leaking memory

I am currenty seeing a problem with memory leaks, it seems to come from this code: - (void)drawRect:(CGRect)rect { CGImageRef cgImage = CGBitmapContextCreateImage(offScreenBuffer); UIImage *uiImage = [[UIImage alloc]…
Radim Halfar
  • 147
  • 1
  • 12
2
votes
2 answers

iPhone - UIView adding a subView vs drawRect?

What are the differences between adding a view as a subView VS drawing the view in that view's drawRect method?. I use both approaches, but I was wondering apart from the obvious such as, if you do in drawRect it will be a single View, as opposed as…
Oscar Gomez
  • 18,436
  • 13
  • 85
  • 118
2
votes
1 answer

How to make a shape appear on top of an image when mouse is clicked?

I'm aiming for the appearance of a rectangle when the mouse is clicked. Here's a snippet of my current code: try{ image = ImageIO.read(file); g.setColor(new Color(255,0,0)); g.drawRect(x, y, 100, 100); …
alicedimarco
  • 325
  • 1
  • 5
  • 20
2
votes
1 answer

Drawing more than one line/path on iPhone using Array of points

I'm trying to create a drawing view by drawing the line(s) using an Array of CGPoints. I'm currently able to draw more than one line but the problem is that I don't know how to break each line when touch is ended. The current status is - line1 is…
Dudi
  • 45
  • 1
  • 8
2
votes
0 answers

setNeedsDisplay does not call drawRect

when my program starts for the first time, drawRect is automatically called and it prints the view. When I call setNeedsDisplay, it does not call drawRect. I have the IBOutlet correctly linked to the view and associated the view to the correct…
user953252
  • 21
  • 2
2
votes
2 answers

drawRect on iPad causing memory problems

I have a 5-tab Tab Bar Controller iPad application. One of the tabs (EKG) is causing memory issues. I have run Instruments and all that I can see is that malloc allocations are constantly increasing and after about 12-mins all of my View Controller…
2
votes
1 answer

Core Graphics- drawRect: not getting called frequently enough

In my application, I have a UIViewController with a subclassed UIView (and several other elements) inside of it. Inside of the UIView, called DrawView, in my drawRect: method, I draw a table grid type thing, and plot an array of CGPoints on the…
Josh Sherick
  • 2,161
  • 3
  • 20
  • 37
2
votes
2 answers

iOS: Faster to call setNeedsDisplayInRect twice when there are two small, non-adjacent areas of the view that need redrawing?

Assume that two very small areas of my view need to be redrawn. One is in the upper left corner, the other in the bottom right. I could use their coordinates to pass a single large CGRect that contains both areas to setNeedsDisplayInRect, but this…
maxedison
  • 17,243
  • 14
  • 67
  • 114
2
votes
2 answers

How to use drawRect to draw in a existing view?

I'm doing a GPS tracking app. Every time it receives a Latitude/Longitude it converts it to (x,y) coordinates and calls drawRect to draw a line between two (x,y) pairs. However, the drawRect method just clear all the old contents before it draw new…
Kin
  • 21
  • 1
  • 3
2
votes
0 answers

Multiple draw requests dynamically iPhone

I'm attempting to make guider/tip boxes for the iPhone as part of a tutorial framework i'm making. I've followed and combined two codes i've found…
Elmo
  • 407
  • 4
  • 15
2
votes
1 answer

Draw rect over camera preview

I have a camera preview where i get every frame, for each frame i analyze the objects inside and i have a list that contain every object recognized and the location, so i have already the locations for every single object. Now i want to draw a rect…
Fanto
  • 377
  • 3
  • 14
2
votes
1 answer

How to update my custom UIView with drawRect?

I'm trying to build some iOS apps while learning and am having some trouble understanding the proper way to do this. What I have currently is a view that is a subclass of UIView. It is clear and I want to use it as a drawing surface. It will sit on…
Nathan Hess
  • 741
  • 1
  • 8
  • 18
2
votes
1 answer

drawRect makes scrolling slow in UIScrollView

I've got a UIScrollView with a (custom) UIView inside of it. In my scrollViewDidScroll-method I'm calling [myCustomView setNeedsDisplay]; This makes the scrolling noticeably slower, if I'm implementing the drawRect: method in my custom UIView -…
swalkner
  • 16,679
  • 31
  • 123
  • 210
2
votes
1 answer

Ring of circles within a circle, dynamically sized

all. Sorry if this has been asked and answered already, I couldn't find this specific problem when I did my search. I am trying to create a circle class that dynamically creates a ring of circles within a circle, and am having issues with the trig…
stoonfish
  • 21
  • 3
2
votes
1 answer

drawRect's aRect argument in relation to UIView's bounds

I'm working on creating my first custom UIView and learning about the semantics of the drawRect method. I have encountered advice (advice that makes sense to me) to only draw within the scope of the CGRect that is passed in as an argument, rather…
pohl
  • 3,158
  • 1
  • 30
  • 48