drawrect

iPhone: How can you draw a piece of an image

Code sample - (void)drawRect:(CGRect)rect { [super drawRect:rect]; CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSaveGState(context); CGContextTranslateCTM(context, 0, self.frame.size.height); CGContextScaleCTM(context, 1.0, -1.0); CGContextDrawImage(context, CGRectMake(0.0, 0.0, self.frame....

Flex/Actionscript image display problem.

I'm trying to extend the Image class but hit a problem that I can't get past. I have a private image (img) that loads an image and a function that takes that image and copies it onto the parent. The debug function "copyit2" displays the image fine (so I know it's loaded OK). But the function "copyit" doesn't work - it just displays a wh...

Making a Grid in an NSView

I currently have an NSView that draws a grid pattern (essentially a guide of horizontal and vertical lines) with the idea being that a user can change the spacing of the grid and the color of the grid. The purpose of the grid is to act as a guideline for the user when lining up objects. Everything works just fine with one exception. Whe...

UIView drawRect: when you draw a line, the rect area will be clear so the previous drawing is gone

It is quite hard to tell so I upload an image to show my problem: http://i42.tinypic.com/2eezamo.jpg Basically in drawRect, I will draw the line from touchesMoved as finger touches and I will call "needsDisplayInRect" for redraw. But I found that the first line is done, the second line will clear the rect part, so some previouse drawing...

iPhone - setNeedsDisplay doesn't call drawRect

Hi everyone, I have seen many posts about this problem but didn't get an answer. I have a controller which view is added to the main window. The controller's view has a subview which has a drawRect. The problem is that this function is never called even if I call [self setNeedsDisplay]. Thanks ...

How to Call drawRect programmatically in objective c

How to Call drawRect programmatically in objective c ? I want to call drawrect method of a view in my UItabbarcontroller. How i can do this ? Thanks in advance.. Edit I have to call when the view is not visible currently. It will be the first time i have to call that view ...

EXC_BAD_ACCESS in drawRect

Hi, The code below "sometimes" causes a crash (EXC_BAD_ACCESS) when run on the device. Never on the simulator. To reproduce it I keep overlaying a modal view controller over my table view controller. It usually happens when the modal view controller is dismissed. Any ideas why this happens? CGContextRef context = UIGraphicsGetCurrent...

why drawRect method is not being called?

#import <UIKit/UIKit.h> @interface quartzViewController : UIViewController { IBOutlet UIView *myView; } @end #import "quartzViewController.h" @implementation quartzViewController -(void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSelectFont(context, "Arial", 24, kCGEncoding...

iPhone NSString drawAtPoint linebreakmodeWordWrap

Hello, Since I had a very slow scrolling tableView I'm now trying to catch up with the direct draw method, similiar to the Tweetie App sample or Apples TableViewSuite code. So right now I'm struggling to draw NSString with more than one line. I'm using the [NSString drawAtPoint: forWidth: withFont: linebreakMode:] method, and it "brea...

Custom UITableviewcell, CGGradient still shows when cell is selected?

I'm using a custom tableview cell (like Tweetie's fast scrolling) i've added a gradient to the context, which looks really nice, but when I select the cell, the gradient is still visible. I'm not sure how to go about removing the gradient when the cell is selected? any ideas? cheers Nik - (void)drawContentView:(CGRect)r { CGContext...

How do I not override old drawings in my iPhone app?

Hi guys, I'm trying to make a "MSPaint" app in iPhone. I am trying to use circles to draw solid circles (which i've done successfully), and then build an eraser by drawing transparent circles. Can someone help me out here? I am kind of stuck. Thanks guys. #import "ImageView.h" #import "EraseViewController.h" @implementation ImageVie...

How can I fill a rect with an alpha color using CoreGraphics?

In my drawRect method, I am drawing a PNG image. On top of that, I want to draw a rect with a 20% alpha color, like this: [[UIColor colorWithWhite:0.0 alpha:0.2] set]; UIRectFill(rect); The problem is, that the alpha property seems to get ignored. No alpha is applied at all, just a black rectangle is drawn. How can I fix this? Thanks ...

Need to override drawrect if your UIView is merely a container?

According to Apple's docs, "Subclasses need not override -[UIView drawRect:] if the subclass is a container for other views." I have a custom UIView subclass that is indeed merely a container for other views. Yet the contained views aren't getting drawn. Here's the pertinent code that sets up the custom UIView subclass: - (id)initWithF...

Can't draw UImage in UIView::drawRect

I know this seems like a simple task, which is why I don't understand why I can't get the image to render. When I set up my UIView, I do the following: myUiView.backgroundColor = [UIColor clearColor]; myUiView.opaque = NO; I create and retain the UIImage in the init function of my UIView: image = [[UIImage imageWithContentsOfFile:[[...

How to fill a path with gradient in drawRect:?

filling a path with a solid color is easy enough: CGPoint aPoint; for (id pointValue in points) { aPoint = [pointValue CGPointValue]; CGContextAddLineToPoint(context, aPoint.x, aPoint.y); } [[UIColor redColor] setFill]; [[UIColor blackColor] setStroke]; CGContextDrawPath(context, kCGPathFillStroke); I'd like to draw a gradient...

Is drawRect: called on multiple threads when using a CATiledlayer?

I know that drawLayer: and drawlayer:inContext: are called on multiple threads when using a CATiledlayer, but what about drawRect:? Apple's PhotoScroller example code uses drawRect: to get its images from disk, and it has no special code for handling threads. I am trying to determine whether my model for a CATiledLayer must be thread-s...

ViewController and drawRect

Hello, I have a UIViewController and I would like it to call drawRect so i can draw on the view but nothing happens. #import <UIKit/UIKit.h> @interface ViewController : UIViewController { ...code... } @end and the implementation #import "ViewController.h" @implementation ViewController -(void) drawRect:(CGRect) rect { draw a po...

Performance issue with DrawRect and NSTimer

I'm trying to make a slot machine animation where the reels spin. to do this, I'm using drawRect to draw images in a custom class that inherits from UIView. I'm using an nstimer to update the position of the images and calling [self setNeedsDisplay] to update the drawing. In the simulator, it looks very good, however, on the device, it i...

UIScrollView scrolling not proper

Hello, I have a UIViewController subclass which has the view property set to a UIScrollView subclass (say ProfileScrollView). Now, I have overridden drawRect: method, in which I draw a lot of text and place UIButtons as subview in between texts. Depending on the text data, I set contentSize of the scrollView in this drawRect: method. Now...

How to properly transform a UIView with a custom drawRect method

Hi I've written a UIView subclass which adds a nice soft shadow underneath a png image. I'm overriding the drawRect method to draw the image and add the shadow. Now, when I try to do a scale/rotate-affine transform on the UIView (by calling the .transform method), I'm not getting the result I'm looking for due to the initial "flattenin...