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

drawing wont scroll with text in drawRect

As a newbie in iOS programming, i'm sorry if this question sounds stupid. I draw some rects to mark some text in a UITextView. The only problem is the rects wont scroll with the text. They just stay there. here is the code: -…
long long
  • 122
  • 8
2
votes
1 answer

Animate sine wave

i'm trying to animate a sine wave in a small frame, i have searched a lot on SO and on the web, but the only goal that I was able to reach it's draw a static sine wave that translate from one side to another side, but doens't want a translation i…
Piero
  • 9,173
  • 18
  • 90
  • 160
2
votes
2 answers

How can i call this method in self.view?

I am making this method for drawing line now what I want is to call it in another methods how can I do that, please help me out of this that how can I add this in self.view? - (void)drawRect:(CGRect)rect { CGContextRef context =…
user1986441
2
votes
3 answers

iphone - Draw a line in UITableViewCell when background view is set

I have written drawRect as follows. -(void)drawRect:(CGRect)rect { [super drawRect:rect]; CGContextRef cxt = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(cxt, 2.0); CGContextSetStrokeColorWithColor(cxt, [UIColor…
Durgaprasad
  • 1,910
  • 2
  • 25
  • 44
2
votes
0 answers

drawInRect a transparent PNG image :Objective C

I have a background view with an image which fill all the view. Above this view, I added another view with backgroundColor [UIColor clear] and the attribute opaque to NO. Here is what I would like to happen: Here is what happens instead: I want to…
2
votes
2 answers

Animating a box drawn in drawRect via CGMutablePathRef

my aim is to drow an empty rounded box, that should appear as a hole, onto my UIView to show what's under. I made this by overriding drawRect method as shown below. This gives me the ability to create a rounded rect of the size of my holeRect…
dev_mush
  • 2,136
  • 3
  • 22
  • 38
2
votes
2 answers

setNeedsDisplay only gets called once

In my code I want to "animate" a delay of drawing a line, so after adding a new line to the view, I call setNeedsDisplay - which works fine once. Inside the drawRect method I draw the line and call a method of the line to increment the line-lengthl.…
2
votes
1 answer

shadow does not show in drawRect:(CGrect)rect,objective

My goal is 1. add gradient for my view (done) 2. add drop shadow for the bottom edge of my view ( issue at here ) What I am doing is : - (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); UIColor…
tranvutuan
  • 6,089
  • 8
  • 47
  • 83
2
votes
3 answers

IOS 6 - Custom UIButton how to give my titleLabel a margin?

I'm drawing an inset rectangular border to my UIButton subclass inside the drawRect: method. As you can see that shape is too close to my button titleLabel frame. How can I set the titleLabel's max width/margin to avoid this? DrawRect: method -…
luca
  • 36,606
  • 27
  • 86
  • 125
2
votes
2 answers

NSView Subclass drawRect gets called in an infinite Loop

I created a Subclass a of NSView to create a custom UI including a NSTextView. Therefore I use the drawRect Method to draw my UI. I also created a Subclass of NSImageView to get a mousedown Event. Whenever I click into my Subclassed NSImageView the…
user99070
2
votes
1 answer

drawRect Doesn't want to draw anything

I have a ViewController on storyboard. I have used the interface builder to set a toolbar at the bottom of the screen. I have set the custom view to a view overrides drawRect. However, for the life of me, I cannot get anything ever to show up on…
jab
  • 5,673
  • 9
  • 53
  • 84
2
votes
1 answer

iOS: How to draw a line between two moving objects?

I basically have an array of UIView objects that are on screen. They are being moved randomly around and I would like to have a line connecting each object. In my drawRect method of the UIView that contains all the moving objects, I draw the lines…
jbender4128
  • 113
  • 1
  • 12
2
votes
0 answers

Figuring out what rects have been invalidated in drawrect after doing multiple setneedsdisplayinrect

I'm drawing images in a grid formation. Some of the images will move, and I need to update the display, but obviously, I don't want to refresh the whole screen unnecessarily. I am using SetNeedsDisplayInRect multiple times but sometimes, it seems…
Nelson Ko
  • 247
  • 4
  • 11
2
votes
2 answers

Custom Drawing of Alpha Images

I am trying to do custom drawing of an image(with alpha) and eventually going to apply different color tints to it. Right now I am just trying to draw it correctly. This might be simple problem but the result is the ALPHA on my image is black. Image…
CodeMonkey
2
votes
2 answers

How do I prevent duplicate code inside 2 drawRect: methods?

I have a few lines of drawing code that are duplicated in two different subclasses. When I move this drawing code to its own class and then call it from within drawRect: it is called but it is never drawn to the screen. What is the right way…
Mike T
  • 1,163
  • 1
  • 11
  • 27