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

Objective c - Draw image with rounded corners in drawRect

I have a UITableViewCell subclass with a UIImage as property. I want to draw the image in drawRect, and to be efficient because this is a table view cell. I know how to draw the image as it is: -(void)drawRect:(CGRect)aRect { CGRect rect =…
Eyal
  • 10,777
  • 18
  • 78
  • 130
4
votes
3 answers

On iOS, setNeedsDisplay really doesn't cause drawRect to be called... unless CALayer's display or drawInContext finally calls drawRect?

I don't really understand how CALayer's display and drawInContext relate to drawRect in the view. If I have an NSTimer that sets the [self.view setNeedsDisplay] every 1 second, then drawRect is called every 1 second, as shown by an NSLog statement…
Jeremy L
  • 3,770
  • 6
  • 41
  • 62
4
votes
1 answer

Draw gradient like UITabBar with tintColor in code

UITabBar by default draws a subtle gradient: I would like to replicate this look and feel in my code with any given tintColor. Just to make it clear: I do not want to set a tintColor on UITabBar (which is possible since iOS 5), I would like to draw…
myell0w
  • 2,200
  • 2
  • 21
  • 25
3
votes
4 answers

How to darken a PNG?

I may point out that Drawing and Rendering in Objective-C is my weakness. Now, here's my problem. I want to add a 'Day/Night' feature to my game. It has got lots of objects on a map. Every object is a UIView containing some data in variables and…
David Da Silva Contín
  • 1,051
  • 2
  • 10
  • 20
3
votes
1 answer

Animate a UIView's CoreGraphics/drawRect content

Is it possible to animate a UIView's CoreGraphics content? Say I have a UIView subclass called MyView that implements the drawRect: method like so: - (void) drawRect: (CGRect) rect { CGContextRef c = UIGraphicsGetCurrentContext(); …
Barjavel
  • 1,626
  • 3
  • 19
  • 31
3
votes
2 answers

iOS -- drawRect sometimes getting called on unexpectedly large rectangle

I have a simple test app. The app consists of the app delegate, a view controller, and a view. The app delegate just starts up the view controller and adds its view to the window. The view controller in turn loads the view at startup and does…
William Jockusch
  • 26,513
  • 49
  • 182
  • 323
3
votes
2 answers

How to draw a String inside a filled rectangle?

I just want to display my String inside a rectangle filled with black. Thanks for the help!
alicedimarco
  • 325
  • 1
  • 5
  • 20
3
votes
1 answer

How to create a rectangle in a rectangle?

In my paintComponent, I have drawRect, which draws a single rectangle. However, I want to make the outline of the rectangle thicker but I don't know how. So I thought of making another rectangle inside the existing one. I tried putting another…
alicedimarco
  • 325
  • 1
  • 5
  • 20
3
votes
0 answers

How can I draw an NSString (using drawInRect) in front of a layer instead of behind?

In my view's initWithFrame I create a root layer, and then add a sublayer to it. I set the sublayer's path so it will draw a colored box. I want to have text appear on top of the box, so in my view's drawRect, I use NSString's drawInRect method to…
ryleigh
  • 218
  • 2
  • 11
3
votes
1 answer

Maintaining UIBezierPath above CAShapeLayer

I have a circle added to CAShapeLayer and a line with UIBeizerPath. I want to maintain the position of line to be above circle. Basically in drawRect, position of the items will be maintained one after the other. So, I call drawCircle() first and…
iOS
  • 3,526
  • 3
  • 37
  • 82
3
votes
1 answer

Does drawRect: automatically check whether something is within the bounds of the CGRect passed to it?

I'm wondering whether I need to check if something is within the bounds of the CGRect passed to drawRect:, or if drawRect: automatically handles that for me. For example, assume that I have 10 UIBezierPaths on the screen. Each curve is in an…
maxedison
  • 17,243
  • 14
  • 67
  • 114
3
votes
1 answer

Refresh draw function without removing sub layers

I tried to create an activity graphs, like the activity graph on Apple watch. (3 rings with animation) here is my full code: private(set) var animationTime: [CFTimeInterval] = [1, 1, 1] private(set) var values: [Double] = [0, 0, 0] private(set) var…
Martin sku
  • 101
  • 7
3
votes
3 answers

Is there any performance loss when repeatedly calling UIGraphicsGetCurrentContext

I'm building a UIView with a custom drawRect function. This is a fairly complex view, with a number of different items that need to be drawn. I've basically broken it down into one function per item that needs to be drawn. What I'm wondering is…
Ben Williams
  • 4,695
  • 9
  • 47
  • 72
3
votes
2 answers

Problem between context and thread in drawRect

I'm trying to draw a couple of UIImages in a UIView, and I'm doing it by hand with drawRect:. Given that the images are dynamically downloaded from the web, I create an NSOperation and I perform the image loading code from a second thread, in order…
ferostar
  • 7,074
  • 7
  • 38
  • 61
3
votes
4 answers

UIView Fill color

I have added a UIView to the nib file. I want to fill that UIView with a color in drawRect method. How can i do this?
Priya
  • 61
  • 1
  • 6