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

Why does my UIView subclass not redraw after I call setNeedsDisplay?

I have a custom UIView which is a sub-view of a UITableViewCell. When the cell is drawn, so is my custom view, correctly calling drawRect: in my UIView sub-class. When the cell is reloaded, the view is drawn correctly (drawRect: is called). When a…
Matt Connolly
  • 9,757
  • 2
  • 65
  • 61
3
votes
1 answer

How to draw a straight line with the given length and angle?

I have to draw a straight line starting at 0,0 with some length and angle(from the top of view). Currently able to create a line by giving starting and ending points but instead of ending points, I have to use angle and length, any help? Here is the…
3
votes
1 answer

drawRect: speed and CGContextDrawRadialGradient (super slow?)

I'm having problems with my UIView subclass' drawRect: function. I use CGContextDrawRadialGradient() in it, and it. When the user drags my UIView it struggled to keep up if I include the gradient. Using Time Profiler I see that literally > 98% of my…
Kenny Winker
  • 11,919
  • 7
  • 56
  • 78
3
votes
1 answer

Custom UITableViewCell and animation on setSelected:animated:

I have a UITableViewCell subclass that does its drawing in a drawRect: method. The whole rectangle is custom drawn, including the background. I was able to get very complex cells while keeping the scrolling very smooth. My problem: I call [table…
mips
  • 278
  • 1
  • 5
  • 9
3
votes
1 answer

Where to setup a UIView subclass' subviews?

I have a simple UIView subclass where I place a UILabel within, in order to give such UIView a certain frame, background color and text format for its label from a UIViewController. I'm reading the View Programming Guide for iOS but there are some…
AppsDev
  • 12,319
  • 23
  • 93
  • 186
3
votes
2 answers

black box around drawRect shape swift

I'm trying to learn Core Graphics and I have having this problem when using drawRect. (picture below) I made a class that inherits from UIView which has the drawRect code. From my viewcontroller class, I than set the dimensions and add the…
Andrew
  • 391
  • 3
  • 15
3
votes
1 answer

Making UIView foreground transparent

I am modifying an IOS app to allow an additional background layer. All the existing overlays are UIImageViews, which handle transparency just fine. The existing background is the main UIView. I want to change the black background to transparent, to…
Peter Webb
  • 671
  • 4
  • 14
3
votes
1 answer

iOS: Why UIView's drawRect has better performance than CALayer's drawInContext

I am currently learning drawing with UIView and CALayer. I quickly did a drawing app to experiment with the two classes. I noticed CALayer had worse performance than UIView. Here is the code: myView.m @interface myView() @property (nonatomic,…
crab oz
  • 635
  • 7
  • 16
3
votes
1 answer

pyQt4 drawing a rectangle when a button is clicked

The Objective I am attempting to draw a rectangle in my window when a button is clicked. The Problem When I use the button to allow the rectangle to be drawn it draws the rectangle just behind the button: Rectangle behind button image If I minimize…
Xorgon
  • 498
  • 1
  • 5
  • 20
3
votes
0 answers

How to properly transform a UIView with a custom drawRect method

I've written a UIView subclass which adds a nice soft shadow underneath a png image. I'm overriding the drawRect method to draw the image and add the shadow. Now, when I try to do a scale/rotate-affine transform on the UIView (by calling the…
polyclick
  • 2,704
  • 4
  • 32
  • 58
3
votes
1 answer

android drawRect not drawing anything

I've run into a wall with this basic drawRect not showing anything and I cannot figure out why. onDraw protected void onDraw(Canvas canvas) { canvas.drawBitmap(canvasBitmap, 0, 0, canvasPaint); canvas.drawCircle(circle1x, circle1y,…
Domiq
  • 77
  • 2
  • 8
3
votes
2 answers

Swift : How to create a UIView with transparent circle in the middle?

There are some answers for objective c but did not find any regarding swift. I would like to create a dark view with transparent circle in middle so that user can see the subview and interact with it. How can I implement that using swift. More…
Sam
  • 1,101
  • 2
  • 13
  • 26
3
votes
1 answer

Adding a curve to my rectangle

I am trying to draw a Yin-Yang in Objective-c and I am having trouble figuring out how to do it. I created two rectangles that are connected. I am having trouble figuring out how to make the lines of my rectangle curve so I can make a circle out of…
Cory
  • 145
  • 4
  • 12
3
votes
1 answer

CGContextShowGlyphsAtPoint DEPRECATED

After spending quite a bit of time to display "Thai Phonetic YK" fonts in an iPhone app. I finally got things sorted out and working. Though it is functionning there is still a complaint (warning) from the compiler about one line of code in the…
Michel
  • 10,303
  • 17
  • 82
  • 179
3
votes
2 answers

iPhone CALayer Stacking Order

I'm using CALayers to draw to a UITableViewCell. I'm trying to figure out how layers are ordered with the content of the UITableViewCell. For instance: I add labels to the UITableViewCell in my cellForRow:atIndexPath method In the drawRect method…
Brian
  • 3,571
  • 7
  • 44
  • 70