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
7
votes
4 answers

Crosshatch in IOS using CoreGraphics?

How would one crosshatch (apply a set of parallel lines at 45 degrees) across the fill of a shape in IOS using core graphics? Sample code? (I'm specially interested in use with an MKPolygon in MKMapKit, however for the moment just trying to see…
Greg
  • 34,042
  • 79
  • 253
  • 454
7
votes
3 answers

drawRect over subviews?

I created a container view that holds a bunch of child views - a collection view, a custom toolbar and some bits and pieces. The design has a border on the top, left and right sides, but not the bottom, so I overrode drawRect to include…
Jasper Blues
  • 28,258
  • 22
  • 102
  • 185
7
votes
1 answer

drawRect not called when using auto layout

I'm converting a view from shocks and struts to autolayout but now the custom drawing code that is in drawRect is not being called. Is this expected behavior and if so how can I work around this?
adam0101
  • 1,198
  • 2
  • 16
  • 24
7
votes
2 answers

Why custom drawRect is not shown in 6.1 simulator?

There is a UIView subclass (ThumbView) inside a UICollectionViewCell. The following code works great in iOS 7 simulator: - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { …
ohho
  • 50,879
  • 75
  • 256
  • 383
7
votes
1 answer

setNeedsDisplay not firing DrawRect

I have a viewController which is obviously a subclass of UIViewController called MapViewController. In this viewController I use GPS to get the location of the user. I also have a view called DrawCircle. This view is a subclass of UIView. Using…
Johnrad
  • 2,637
  • 18
  • 58
  • 98
7
votes
4 answers

UIView overriding drawRect causes view not to obey masksToBounds

I am trying to override the drawRect: method of UIView in my custom view. However, my view has a border radius defined as: sub = [[[NSBundle mainBundle] loadNibNamed:@"ProfileView" owner:self options:nil] objectAtIndex:0]; [self…
Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389
7
votes
2 answers

setNeedsDisplay does not trigger drawRect in subviews as expected

I'm struggling with setNeedsDisplay. I thought it was supposed to trigger calls of drawRect: for the view for which it is called and the hierarchy below that if it's within the view's bounds, but I'm not finding that to be the case. Here is my…
Victor Engel
  • 2,037
  • 2
  • 25
  • 46
6
votes
3 answers

iOS 5 UIView drawRect override not working on device

I'm preparing my iPhone app to publish on iOS 5 GM and came across a bug with UIView. When I override the drawRect method on a subclass, the Simulator shows the desired result but when I try to test on an actual device, the drawRect override doesn't…
Jay
  • 71
  • 1
  • 3
6
votes
4 answers

subclassed UITableViewCell - backgroundView covers up anything I do in drawRect

I'm trying to make a subclassed UITableViewCell where I draw an image in the upper right corner. I have it working perfectly - except when I set self.backgroundView, my background image covers up the image drawn in drawRect. There must be a way to…
Jim Rhoades
  • 3,310
  • 3
  • 34
  • 50
6
votes
3 answers

Making a Grid in an NSView

I currently have an NSView that draws a grid pattern (essentially a guide of horizontal and vertical lines) with the idea being that a user can change the spacing of the grid and the color of the grid. The purpose of the grid is to act as a…
Hooligancat
  • 3,588
  • 1
  • 37
  • 55
6
votes
2 answers

UIView draw rect retain's the previous drawing and does not clear on view.transform

I have the following code to show marker in a UIView. The marker show's well, and once we try to pinch zoom and scale the UIView using the transform the first drawing remains as it is, even after calling setNeedsDisplay. My Custom UIView subclass…
NNikN
  • 3,720
  • 6
  • 44
  • 86
6
votes
1 answer

MKAnnotationView disappearing on swipe and double-tap zoom

I have subclassed MKAnnotationView to create an annotation that basically draws a circle around a point on a map view through override of drawRect. The circle draws fine in the following situations (in the simulator): On initial load of the map…
Steve N
  • 2,667
  • 3
  • 30
  • 37
6
votes
3 answers

UITableView Did Load (Done drawing the cells)

Question How can you detect when the Table View is done drawing the cells? Issue I got two labels within the contentView of an UITableViewCell. The size of these labels are dynamic. I was able to do so by subclassing UITableViewCell, in the drawRect…
Mark
  • 16,906
  • 20
  • 84
  • 117
6
votes
2 answers

Having UIView drawRect occur in a background thread

I would like to have a UIView subclass that implements a method similar to setNeedsDisplay, except that redrawing (i.e., that would usually be called via drawRect:) will occur in a background thread sometime soonish, rather than at the end of the…
Benjohn
  • 13,228
  • 9
  • 65
  • 127
6
votes
2 answers

Can I draw shapes like circle,rectangle,line etc outside drawRect method

Can I draw shapes like circle, rectangle, line etc outside drawRect method using CGContextRef contextRef = UIGraphicsGetCurrentContext(); or is it mandatory to use it inside drawRect only. Please help me, let me know how can I draw shapes outside…
Prashant Nikam
  • 2,253
  • 4
  • 17
  • 29