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

Animation for drawRect drawings

A part of my app is a statistics-function. I draw in a UIView a path and fill it with a color... now I want to make an animation that the path draws through the UIView from the left side to the right side. I read about CALayer, but I'm not sure how…
Christian 'fuzi' Orgler
  • 1,682
  • 8
  • 27
  • 51
9
votes
3 answers

How to detect touches on a draggable line (drawn using drawRect)

Calling all experts! I have seen various posts, and to be honest, my need is a little different than the answers available on SO. I want to create a UI where the user can create various lines (straight, curved, wiggled etc) onto a specific area…
Gurtej Singh
  • 3,244
  • 1
  • 14
  • 27
9
votes
2 answers

Clear UIView of drawing?

I am using a subclass of UIView to draw, this subclassed view is used to get your signature on a view controller. There is a clear button which is supposed to clear the UIView except it doesn't work. Here is what I have…
Josue Espinosa
  • 5,009
  • 16
  • 47
  • 81
9
votes
3 answers

Passing parameters to drawRect

I have a couple of UIView classes all drawing the same thing but in different colors and alpha settings. I've tried to pass parameters but cannot figure out how to get the drawRect part where I need to be. I draw like this: CGRect positionFrame =…
sangony
  • 11,636
  • 4
  • 39
  • 55
8
votes
3 answers

NSScrollview and transparent, overlay NSScroller subclasses

I have made a slick NSScroller subclass, but can't figure out how to make it overlay on top of the NSScrollView instead of pushing the documentView aside. Here you can see the background of a NSCollectionView that I wish to make 100% wide, and have…
coneybeare
  • 33,113
  • 21
  • 131
  • 183
8
votes
3 answers

Multiple rectangles not drawing on canvas

I am trying to create a family tree like structure in android. I am using canvas to draw rectangle and line for family members names and connecting line. I am drawing rectangle and line by the following method with the help of…
Manishika
  • 5,478
  • 2
  • 22
  • 28
8
votes
2 answers

How to add round corner to canvas drawrect in Android?

I am creating a rectangle in @Override method of ReplacementSpan. How to add RoundCorner and padding to it? Code: @Override public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) { …
user478489
8
votes
0 answers

CADisplayLink and drawRect

I need help to better understand how CADisplayLink and drawRect behave, so that I can figure out how to keep my app's framerate at a smooth 60fps. My (presumably incorrect) understanding so far is the following: 1) CADisplayLink calls a specified…
deltacrux
  • 1,186
  • 11
  • 18
8
votes
1 answer

Black background in UIView?

I followed a tutorial online to draw in a subclassed UIView. The tutorial showed a UIView with a white background, I fixed this by simply changing the super's bg color. The problem is, when touches end, the background does not remain clear. I have…
Josue Espinosa
  • 5,009
  • 16
  • 47
  • 81
8
votes
2 answers

Why an empty implementation of drawRect: will adversely affect performance during animation

I am subclassing my UIView class. The Xcode (I am using 4.6.3) auto generated code says, /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. -…
subhash kumar singh
  • 2,716
  • 8
  • 31
  • 43
8
votes
2 answers

Manually color fading from one UIColor to another

I'm trying to fade one UIColor to another in a drawRect. I've created this function to calculate a color at a certain percentage: - (UIColor *)colorFromColor:(UIColor *)fromColor toColor:(UIColor *)toColor percent:(float)percent { float dec =…
Luke
  • 13,678
  • 7
  • 45
  • 79
8
votes
2 answers

iOS Drawing Circles

I am trying to create the circles below in my iOS app. I know how to make the circles but am not entirely sure on how to get the points along the arc. It has to be in code not an image. Below is also the code I currently have. -…
BDGapps
  • 3,318
  • 10
  • 56
  • 75
8
votes
2 answers

Color difference between drawRect and Interface Builder?

Simply, I have 2 views in interface builder, one is set to the color 99,99,99 using the RGB sliders in interface builder. The other view is colored programmatically to achieve a certain shape. I fill it using: //Obviously, this is in…
Mazyod
  • 22,319
  • 10
  • 92
  • 157
7
votes
2 answers

Getting a glyph boundingRect in draw#rect in UILabel

Using Swift, I want to get the boundingRect of a glyph, in draw#rect in a UILabel. The UILabel already has a size (say 300x300 in the example) and qualities such as the text being centered. class RNDLabel: UILabel { override func draw(_ rect:…
Fattie
  • 27,874
  • 70
  • 431
  • 719
7
votes
3 answers

Mysterious "progressive slowing" problem in run loop / drawRect

Here's a real mystery. Imagine you are doing the conventional process of drawing a complex image offscreen (CGLayer), and you are updating the image on to the screen intermittently as you draw. As you know the way to do this is: run the large…
Fattie
  • 27,874
  • 70
  • 431
  • 719
1 2
3
70 71