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
5
votes
2 answers

How can I fill a rect with an alpha color using CoreGraphics?

In my drawRect method, I am drawing a PNG image. On top of that, I want to draw a rect with a 20% alpha color, like this: [[UIColor colorWithWhite:0.0 alpha:0.2] set]; UIRectFill(rect); The problem is, that the alpha property seems to get ignored.…
Rits
  • 5,105
  • 4
  • 42
  • 53
5
votes
2 answers

Using Core Graphics from ObjectiveC, how to you curve an arrow around a circle?

Our designer has asked me to recreate this: Im subclassing UIView, and I've overridden the drawRect command like this: [super drawRect:frame]; CGFloat x = self.frame.origin.x; CGFloat y = self.frame.origin.y; CGFloat w =…
Ken Corey
  • 435
  • 3
  • 15
5
votes
1 answer

iOS Custom UIView Drawing - CAShapeLayers or drawRect?

I'm new to iOS UIView drawing and I'm really trying to implement a custom UIView class in a standard way. The UIView class that I'm working on now is simple: it has mostly static background shapes that form a composite shape. I also want to add…
user3546182
  • 565
  • 5
  • 6
5
votes
1 answer

Drawing filled circles with letters in iOS 7

The new ios 7 phone app has a favorites section. In that section the names of the contact appear next to a filled in circle with the inital of the contact inside the circle. How is this drawn? With drawrect or is there already and object created for…
cdub
  • 24,555
  • 57
  • 174
  • 303
5
votes
1 answer

How to draw on a transparent NSWindow with a transparent NSView?

I want to draw on the screen with a transparent background, so that everything (e.g. open applications are still visible). In windowDidLoad of my custom NSWindowController i have the follwing: [self.window setOpaque: NO]; [self.window…
mc_plectrum
  • 363
  • 4
  • 12
5
votes
4 answers

How can I draw a curved shadow?

Like so: I know that this will not work with NSShadow, drawing it in drawRect: will work just fine.
IluTov
  • 6,807
  • 6
  • 41
  • 103
5
votes
1 answer

NSImage drawInRect and TemplateImages

In have an NSImage is a template image (that is, [NSImage isTemplate] returns YES). When I use it inside an NSImageView, it is drawn correctly as a template image. However, if I draw it manually using drawInRect:fromRect:operation:fraction:, it is…
TheNextman
  • 12,428
  • 2
  • 36
  • 75
5
votes
2 answers

Weird anti-aliasing in custom view

I have a custom UIView which is drawn using its -[drawRect:] method. The problem is that the anti-aliasing acts very weird as black lines horizontal or vertical lines are drawn very blurry. If I disable anti-aliasing with…
mrueg
  • 8,185
  • 4
  • 44
  • 66
5
votes
2 answers

iOS 6 view hierarchy nightmare

I have an app in the app store with nearly 5-star rating, but when iOS 6 came out, some of the views in in the app's main view hierarchy started blinking. This happens on the app that was in the store (I removed it when iOS6 came out) as well as in…
avance
  • 1,993
  • 2
  • 21
  • 23
5
votes
7 answers

Drawrect with CGBitmapContext is too slow

So I've got a basic drawing app in the process that allows me to draw lines. I draw to an off screen bitmap then present the image in drawRect. It works but its way too slow, updating about half a second after you've drawn it with your finger. I…
EagerMike
  • 2,032
  • 1
  • 24
  • 40
5
votes
2 answers

iPhone: why isn't drawRect getting called?

Okay, I guess I'm missing something important, and I can't seem to find the answer. I'm posting all the code, because it's very small. Can someone please tell me what I'm doing wrong? I've worked on this looking at example after example, for quite…
Carp
5
votes
1 answer

NSOperation: addsubview in the main thread and slowness

I have implemented the following NSOperation, to draw N custom views - (void)main { for (int i=0; i> //(customView is a UIView with some drawing code in drawrect) …
Abramodj
  • 5,709
  • 9
  • 49
  • 75
4
votes
2 answers

How to add a second UILabel to a UIButton, configurable per UIControlState

I want to display 2 strings (at different positions in the button) with different fonts and colors (I'm using the button's setTitle for one, and I need another one), and some attributes must be changed based on the current UIControlState (like the…
Chris
  • 136
  • 7
4
votes
1 answer

Qt drawRect in background

I want to paint the background of a slider. I tried this but the color covers up the whole slider. This is in an inherited class of QSlider void paintEvent(QPaintEvent *e) { QPainter painter(this); painter.begin(this); painter.setBrush(/*not…
Geore Shg
  • 1,299
  • 5
  • 23
  • 38
4
votes
1 answer

How to implement a custom Focus Ring in drawRect for NSTextField or NSTextVew

I want to draw a custom focus ring for my NSTextView subclass (which doesn't have a focus ring by default). I managed to implement it by overriding the parent NSScrollView drawRect and adding this code: - (void)drawRect:(NSRect)dirtyRect { if…
rdougan
  • 7,217
  • 2
  • 34
  • 63