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
1 answer

Drawing graphs on iOS: Use layers or override drawRect?

Reading through the documentation, it's not clear to me if overriding a UIView's drawRect or using layers is appropriate. I am going to be rendering two kinds of graphs. A line graph and a single-bar bar graph. Both will have ticks along the…
Brian
  • 6,910
  • 8
  • 44
  • 82
2
votes
1 answer

Why isn't the "rectangle" that I want to draw on my Qt widget showing up?

I basically want to display a rectangle on a dialog window widget. Using another question as reference, I tried to adapt the framework of using a QLabel and painting to it (the process overall seems overly complicated). I started by making a member…
norman
  • 5,128
  • 13
  • 44
  • 75
2
votes
1 answer

iOS UIImageView vs drawRect image stretching

I was looking at a WWDC video from 2011 about UIKit rendering and there is this section which speaks how UIImageView is more efficient than using drawRect. Here is an example the session shows: I am not so clear on why stretching an image to…
Hetal Vora
  • 3,341
  • 2
  • 28
  • 53
2
votes
2 answers

custom drawing nsview inside nsscrollview

I'm having a problem with custom drawing NSView using as documentView of a NSScrollView. Here is my drawRect: code: - (void)drawRect:(NSRect)dirtyRect { [[NSColor lightGrayColor] set]; NSRectFill(self.frame); // Fill entire frame …
fish potato
  • 5,319
  • 6
  • 27
  • 32
2
votes
1 answer

UIGraphicsGetCurrentContext() short lifetime

I have a view which implements freehand drawing, but I have a small problem. I noticed on the iPad 3 that everything went to hell, so I tried to update my drawing code (probably as I should have done in the first place) to only update the portion…
borrrden
  • 33,256
  • 8
  • 74
  • 109
2
votes
0 answers

DrawRect called once in subview

Newbie to Xcode. set up a view controller with some custom buttons and text fields. added a small UIview window as a subView in my main view to draw a graph in. updating the graph by calling [self.mySubView setNeedsDisplay] in various methods in my…
Pencil
  • 65
  • 1
  • 7
2
votes
1 answer

Property not set in drawRect method - iOS

I have been seeing some strange behavior when I try to access a class variable or a property in my drawRect method.. In my .h file I have the following @interface DartBoard : UIView { Board * board; int index; } @property (readwrite, assign,…
damien murphy.
  • 371
  • 2
  • 16
2
votes
2 answers

On iOS, if a view has several layers, can drawRect just choose a layer to display?

On iOS, if a view has several layers, then can the drawRect method just choose any one layer to display, and 1 second later, choose another layer to display, to achieve an animation effect? Right now, I have several layers, but I don't think they…
Jeremy L
  • 3,770
  • 6
  • 41
  • 62
2
votes
1 answer

CGContextDrawLinearGradient versus cagradientlayer?

What is the difference between CGContextDrawLinearGradient, called in a UIView's drawRect method, and a CAGradientLayer? How do they compare performance wise? What is the best practice for creating gradient views? I'd really like a nice explanation…
Stephanie
  • 145
  • 1
  • 6
2
votes
1 answer

Why CGLayers are not blending?

Why obj2 not blend with obj1 but without use CGLayer it works fine,same problem with CGContextDrawLayerAtPoint,Does CGLayer not support CGContextSetBlendMode?? //Layer CGContextRef context = UIGraphicsGetCurrentContext(); CGLayerRef…
2
votes
2 answers

drawRect see empty array

Button in drawtestViewController.m is linked to pushPoint action in ChalkBoard.m. It populates pointArray with CGpoint objects. This array is full of objects everywhere, except when viewed from drawRect. It seems as from drawRect I'm somehow…
Janis Jakaitis
  • 327
  • 1
  • 8
1
vote
1 answer

Encapsulate the way a particular type of brush is drawn in Objective-C

I am making a drawing app for iOS and I have the following classes: CanvasViewController holds a CanvasView and allows you to select a Brush for use in drawing CanvasView is a UIView that contains a background color and an array of Stroke that are…
tacos_tacos_tacos
  • 10,277
  • 11
  • 73
  • 126
1
vote
0 answers

Clear remnants of drawRect() in custom UIControl

I create a custom slider with using subclass of UIControl. I draw my background and a button in drawRect() but when I redraw my button, there are remnants of previous draw left. How can I clear this? I try to track memory leaks with instruments but…
doc
  • 266
  • 2
  • 15
1
vote
1 answer

UITableViewCell rendering with drawRect: appears blurry on Retina iPad display

I'm using drawRect: in my UITableViewCell subclass for the rendering performance when scrolling; everything on the cell (text and graphics) is rendered in drawRect:. On the new iPad's retina display, the cell appears very blurry. For comparison,…
Ash Furrow
  • 12,391
  • 3
  • 57
  • 92
1
vote
1 answer

size of UIView based on drawRect

so here's the scenario, I would like to add a UIView in the shape of a irregular polygon on top of another UIView. I draw the irregular polygon using the UIView's drawRect method. I would like to know how to make the frame of the UIView that of the…
stephen
  • 1,617
  • 3
  • 20
  • 27