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

Adding a drop shadow to NSString text in a drawRect: method without using UILabel

I'd like to add a drop shadow to text drawn using the iOS supplied NSString (UIStringDrawing) category method: - (CGSize)drawAtPoint:(CGPoint)point forWidth:(CGFloat)width withFont:(UIFont *)font minFontSize:(CGFloat)minFontSize …
idStar
  • 10,674
  • 9
  • 54
  • 57
21
votes
3 answers

iPhone SDK: How to trigger drawRect on UIView subclass after orientation change?

I am subclassing a UIView and overwrite the drawRect method. I'm noticing that the view's drawrect is only being called when the view first loads. After that it is never called again. How to I make sure it gets called after an orientation change?…
memmons
  • 40,222
  • 21
  • 149
  • 183
18
votes
2 answers

drawrect Vs layoutsubviews - NSView - Cocoa touch

I can't find a decent answer to explain me the difference between these 2 functions. when does every one gets called, and how does one different then the other ? for example , can't I just layout my views inside drawrect ? Thanks
Idan
  • 5,717
  • 10
  • 47
  • 84
16
votes
1 answer

CALayer renderInContext: Position of Drawing

I have a UIView with a custom shape drawn in drawRect:. The frame property is set to: {5.f, 6.f, 50.f, 50.f} Now, I render the view in an Image Context, but it is ignoring the frame property of the UIView, and always drawing the UIView in the top…
Mazyod
  • 22,319
  • 10
  • 92
  • 157
15
votes
4 answers

How to draw a rectangle?

I want to draw a filled rectangle in my viewContoller's view. I wrote the code below in viewDidLoad. But there is no change. What is wrong? CGRect rectangle = CGRectMake(0, 100, 320, 100); CGContextRef context =…
charly
  • 167
  • 1
  • 1
  • 6
15
votes
4 answers

Swift 3: Drawing a rectangle

I'm 3 days new to swift, and I'm trying to figure out how to draw a rectangle. I'm too new to the language to know the classes to extend and the methods to override, and I've looked around for sample code, but nothing seems to work (which I'm…
Jean Valjean
  • 747
  • 1
  • 9
  • 30
15
votes
2 answers

Drawing a very thin line with CGContextAddLineToPoint and CGContextSetLineWidth

I want to draw a very thin hairline width of a line in my UIView's drawRect method. The line I see that has a value 0.5 for CGContextSetLineWidth doesn't match the same 1.0 width value that is used to draw a border CALayer. You can see the…
Howard Spear
  • 551
  • 1
  • 5
  • 14
14
votes
1 answer

CALayer vs CGContext, which is a better design approach?

I have been doing some experimenting with iOS drawing. To do a practical exercise I wrote a BarChart component. The following is the class diagram (well, I wasnt allowed to upload images) so let me write it in words. I have a NGBarChartView which…
Murali Raghuram
  • 255
  • 2
  • 8
14
votes
2 answers

what is the difference between UIImageView and drawInRect?

I want to display so many images in table cells. I knew two methods to show an image. One is creating an instance to UIImageView and show it CGRect rect=CGRectMake(x,y,width,height); UIImageView *image=[[UIImageView…
Rajkanth
13
votes
2 answers

Swift / UIView / drawrect - how to get drawrect to update when required

I'm new to learning Swift, and am trying to get an incredibly simple app to run. All I'm trying to do is get UIView.drawRect to update when I press a button. It updates/draws when the app first loads, and then nothing after that, whatever I try. …
Tom M
  • 387
  • 1
  • 3
  • 9
11
votes
4 answers

drawRect drawing 'transparent' text?

I am looking to draw a UILabel (preferable through subclassing) as a transparent label, but with solid background. I draw up an quick example (sorry, it's ugly, but it gets the points across :)). Basically I have a UILabel and I would like the…
runmad
  • 14,846
  • 9
  • 99
  • 140
11
votes
2 answers

MKAnnotationView drawRect: not getting called

I've implemented a custom annotation derived from MKAnnotation called ContainerAnnotation and a custom annotation view derived from MKAnnotationView with a drawRect: method called ContainerAnnotationView. For some reason the drawRect: method is not…
David Potter
  • 2,272
  • 2
  • 22
  • 35
11
votes
2 answers

How many ways to calculate the FPS (Frames per second) of an iOS App programmatically?

Since we are talking about programmatically, Instruments are not under my consideration. Some reference listed in advance: Calculate fps (frames per second) for iphone app Display FPS on iOS onscreen (without Instruments) At what framerate does the…
Jason Lee
  • 3,200
  • 1
  • 34
  • 71
11
votes
1 answer

UIBezierPath draw circle with different strokes

Basically I need to have a circle with stroke in different color, all equal in size. For example, 1/2 is blue and 1/2 is red. Image (sorry for so bad image): How can I draw something like this?
Eli_Rozen
  • 1,301
  • 4
  • 20
  • 31
10
votes
2 answers

Drawing MKMapView Overlay like Google Maps Directions

iOS 5 changed the way the built-in Google Maps App draws routes: I would now like to replicate the design of the route overlay in my own app but I am currently only able to draw a plain blue line. I would like to add the 3D-effect with the…
myell0w
  • 2,200
  • 2
  • 21
  • 25
1
2
3
70 71