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

Using circular progress bar with masked image?

I am working on a circular progress bar for custom game center achievements view and I have kind of "hit the wall". I am struggling with this for over two hours and still cannot get it to work. The thing is, that I need a circular progress bar,…
Dominik Hadl
  • 3,609
  • 3
  • 24
  • 58
6
votes
4 answers

Checking if NSButton is down on drawRect

I would like to check if my custom NSButton is currently in a pressed state (the user is clicking down on it) in my custom drawRect method. Something like this: - (void)drawRect:(NSRect)dirtyRect{ if ([self buttonIsInPressedState]) { …
Holger Sindbaek
  • 2,278
  • 6
  • 41
  • 68
6
votes
1 answer

iOS, Draw radial gradient that fills recrangle

The code below draws a perfect elliptical radial gradient, but does not fill in the corners of it's view. How do I get it to draw beyond the edge of the ellipse? The documented option is kCGGradientDrawsAfterEndLocation, but I think it's not…
OWolf
  • 5,012
  • 15
  • 58
  • 93
6
votes
2 answers

UIView Drawing Best Practices

My application is able to do some simple figure's drawing (until I get a more stable code, I am sticking with only one figure) and it's also able to re-size them. The code I use to create a UIView is the following : - (void)drawRect:(CGRect)rect { …
Rui Peres
  • 25,741
  • 9
  • 87
  • 137
6
votes
1 answer

Drawing animation

I'm creating a simple app where when the user presses a button, a series of lines will be drawn on the screen and the user will be able to see these lines drawn in real time (almost like an animation). My code looks something like this (has been…
HHHH
  • 1,197
  • 2
  • 16
  • 28
6
votes
2 answers

iOS CGPath Performance

UPDATE I got around CG's limitations by drawing everything with OpenGL. Still some glitches, but so far it's working much, much faster. Some interesting points : GLKView : That's an iOS-specific view, and it helps a lot in setting up the OpenGL…
F.X.
  • 6,809
  • 3
  • 49
  • 71
6
votes
2 answers

How can store all points in the CGContextAddArc (CGContextRef) to NSMUtableArray

How can i strore all pixel point in the CGContextAddArc To NSMutableArray.or CGContextRef to NSMutable Array static inline float radians(double degrees) { return degrees * PI / 180; } - (void)drawRect:(CGRect)rect { CGContextRef context =…
Musthafa
  • 862
  • 3
  • 12
  • 27
5
votes
3 answers

Drawing Straight Lines with Finger on iPhone

Background: I am trying to create a really simple iPhone app that will allow the user to draw multiple straight lines on the screen with their finger. I'm using these two methods in my UIViewController to capture the coordinates of each line's…
Trevor
  • 4,620
  • 2
  • 28
  • 37
5
votes
5 answers

drawRect performance

I need to draw lots of polygons 500k to a million on the iPad. After experimenting, I can only get only get 1 fps if that. This is just an example my real code has some good sized polygons. Here are a few question: Why don't I have to add the…
Richard
  • 276
  • 3
  • 9
5
votes
2 answers

How can I draw in the "bounce" area of a UIScrollView?

I have a custom-drawn view that I include in a UIScrollView that scrolls horizontally. The view draws a background with lines extending horizontally, and some different background colors. When I scroll to the far left such that the scroll view…
Micah Hainline
  • 14,367
  • 9
  • 52
  • 85
5
votes
0 answers

Metal Render Loop optimization

I'm looking for some direction on how to properly implement a Metal render loop. My render loop is being fed a stream of video frames from an AVPlayer. Here's my current implementation: A CVDisplayLink queries the AVPlayerItemVideoOutput of the…
zzyzy
  • 973
  • 6
  • 21
5
votes
1 answer

Java swing draw rectangle in mouse drag and drop

I am creating a rectangular drawing program.The square is drawn only if the program is dragging to the bottom side. Even if dragging in the other direction, I want to ensure that squares are drawn correctly. How can I fix it? Please help…
Wefljwef Sdfksd
  • 53
  • 1
  • 1
  • 4
5
votes
3 answers

Make 2 contradictory methods work in drawRect

I'm writing an app building elements consisting of CGPoints. I have 2 buttons: makeRectangle and makeTriangle. For building/drawing stage I use three methods for rectangle and three methods for triangle inside drawRect. I'm stuck with my code in…
Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
5
votes
3 answers

UIView drawRect drawing lines of wrong width

I'm trying to add a little red line on the bottom of my UIView. I want the line to be a 1px line. Can someone tell me why the following code: - (void)drawRect:(CGRect)rect { CGContextRef currentContext =…
Ale Morales
  • 2,728
  • 4
  • 29
  • 42
5
votes
1 answer

ios UITableViewCell programmatically create in drawRect vs layoutSubviews

I've been trying to create complex UITableViewCell through Autolayout but it is giving a huge performance lag while scrolling, So I decided to go for frame-based i.e programmatically. The complexity of cell layout is like Facebook cards where every…
Mukesh
  • 3,680
  • 1
  • 15
  • 32