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

NSString font size specific to frame width

I am using drawRect for a text display, calling NSString. I am trying to implement using sizeWithFont to auto resizing font (shrinking) with default font size of 17 and using a loop to reduce the font size by 1 if it does not fit the size of width.…
user2033092
  • 41
  • 1
  • 5
3
votes
1 answer

asynchronous drawing and touches

I have a draw area (UIView), where i draw within the CGContextRef. Ofcourse i am catching touches to draw. While the drawRect method slowly draws lot's of existing objects the touches are not caught. If i call drawing in drawRect in separate thread…
Pheu Verg
  • 230
  • 2
  • 12
3
votes
5 answers

UIView drawRect: Draw the inverted pixels, make a hole, a window, negative space

With the code below I am drawing a rounded rectangle. It draws a nice solid light gray filled rounded rectangle (at the size of "self"). I actually want to draw the pixel inverse of this, that is: not a solid rounded rectangle, but a window or hole…
OWolf
  • 5,012
  • 15
  • 58
  • 93
3
votes
1 answer

iOS: Draw text on UIView with LineWidth 1px

I have a scenario where I will have to draw a text on a UIView. For which my code is - (void)drawRect:(CGRect)iRect { [super drawRect:iRect]; CGContextRef aContext = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(aContext,…
user1280350
3
votes
0 answers

Custom UITableViewCell with different row height and a drawRect

I have a subclassed UITableViewCell and in that class I have a drawRect method that draws a frame for each cell. Each cell have a different size (like in Twitter App) and for some reason this is causing my scrolling to be slow. Is there a way around…
Ahmad N.
  • 33
  • 1
  • 2
3
votes
1 answer

Frame rate compromised with CADisplayLink and drawRect

My question is about iOS development. I am writing a simple game in order to test the low level Core Graphics functions (contexts, layers, etc) and how to mix it with actual simple views... I explain it: I have a simple sprite in the screen, it is…
3
votes
1 answer

Why is CGContextDrawImage in drawRect initially slow?

Consider this simple UIView subclass in an ARC-enabled iOS app that draws on the view when the screen is touched: - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint location = [[touches anyObject] locationInView:self]; …
bryan
  • 2,223
  • 1
  • 22
  • 19
3
votes
1 answer

Rendering NSView to image: cacheDisplayInRect draws transparent areas differently from usual drawRect call

Greetings! I have a problem and Googling brought no results... I implemented the drawRect method for my NSView (subclass) to draw some shadows and semi-transparent fills. Everything looks great! But now I need to create an NSImage from my NSView…
UJey
  • 1,442
  • 11
  • 15
3
votes
1 answer

iOS UIView drawRect resize animation

I tried to override the drawRect method in a simple UIView extension to draw a rectangle with rounded edges and fill it with black color, and also animate the view to resize on touch. The thing is, resizing completely deforms the drawing, as if the…
Avahi
  • 121
  • 1
  • 5
3
votes
2 answers

Rounded Avatar Images on iOS and performance issues

Is there any way to draw rounded UIImages without doing any of the following? Blending (Red in Core Animation Instruments) Offscreen Rendering (Yellow in Core Animation Instruments) drawRect I've tried drawRect with clipping path. This is just…
bogardon
  • 896
  • 2
  • 10
  • 22
3
votes
2 answers

drawRect always wants to update the entire screen when view is shrunken

I have a CGImage that is displayed in an UIView controlled by a UIScrollView. The image is typically 1680*1050 in 24 bit colors without alpha channel. The image is created like this: CGImageRef bitmapClass::CreateBitmap(int width, int height, int…
2
votes
0 answers

UIView's drawRect gets called multiple times after period of inactivity

My iPad application uses a UIScrollView in which I've implemented the drawRect: method. This method updates only the portion of the view that needs to be redrawn. The content that needs to be drawn changes upon some gesture by the user (like in a…
panbsi
  • 21
  • 3
2
votes
1 answer

create cgpath out of drawRect

I have UIView subclass and I want to draw a CGPath out of the drawRect. I have heard that it is and isn't possible. I understand that the CGPath needs context. I tried to give it context with the newImage. I am also thinking that I have to call this…
Asdrubal
  • 2,421
  • 4
  • 29
  • 37
2
votes
2 answers

iOS set text color in a view's drawrect

I have code that does custom rendering inside of a drawRect method in a UIView subclass. I am trying to render text out using [NSString drawInRect] which works great, however it always shows up in white. After much googling and browsing SO I have no…
Seb
  • 3,414
  • 10
  • 73
  • 106
2
votes
1 answer

Stretchable image in drawRect causes slow scrolling

I am subclassing a UITableViewCell and in the drawRect: method I want to draw a stretchable image but I have experienced that this has a big impact on the scroll performance. Does anyone know how I can use a stretchable image and still have a good…
simonbs
  • 7,932
  • 13
  • 69
  • 115