Tag: core graphics

CAGradientLayer and scrollViewTexturedBackgroundColor

I’m trying to use CAGradientLayer to fade foreground controls against the background textured view. So in a nutshell, I have a view with the bg color as scrollViewTexturedBackgroundColor. I have a view on top of that, whose contents I’d like to fade at the border into the background view’s color. CAGradientLayer* gradient = [CAGradientLayer layer]; […]

Draw a shadow which is hidden under the semi-transparent view?

I have a semi-transparent view with a drop shadow. I mocked it up in photoshop, which doesn’t draw the shadow under the object. Then I made it in xcode, but it obviously does draw the shadow underneath. I was wondering if there’s a way to avoid this. In other words – have the shadow only […]

iPhone UIView replace image color programmatically, like in Photoshop or Illustrator

I have a set of graphics that I would like to reuse within my apps. They are buttons and images with transparency. Rather than having dozens of hard-coded button images, I would love to have a single button image, and be able to assign a color to it dynamically, like the navigation bar and it’s […]

How to find an arrow tip points given origin and end point of a line

Consider you have a line with start point (x1,y1) and end point (x2,y2). In order to draw an arrow cap to the line (in objective-c), I need to find the points of the arrow (x3,y3,x4,y4) given the angle of the arrow (45 degrees), and the length of the arrow tips (h). So given x1,y1,x2,y2,h,alpha whats […]

How to remove the transparent area of an UIImageView after masking?

In one of my iOS applications, I am trying to cut a portion of an image using CGImageMask. I have succeeded in masking the image with the following code: – (UIImage *)maskImage:(UIImage *)referenceImage withMask:(UIImage *)maskImage { CGImageRef maskRef = maskImage.CGImage; CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef), CGImageGetHeight(maskRef), CGImageGetBitsPerComponent(maskRef), CGImageGetBitsPerPixel(maskRef), CGImageGetBytesPerRow(maskRef), CGImageGetDataProvider(maskRef), NULL, false); CGImageRef masked = CGImageCreateWithMask([referenceImage […]

CoreGraphics: Using finger strokes to erase part of image?

I’m working on drawing code to erase part of an image. I’m not an expert on CoreGraphics and could use some help. This routine works fine, however, when moving fast, it loses touches (Not very smooth). Can this routine be modified to make CGContextClearRect smoother? Is there a better, faster way to do this? -(void)drawRect:(CGRect)rect […]

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. […]

Can't draw in UITableViewCell's drawRect

I’m having trouble drawing in the drawRect method of my custom UITableViewCell. Here is the code I am using – (void)drawRect:(CGRect)rect { CGContextRef ctx = UIGraphicsGetCurrentContext(); CGPoint origin = _faceView.frame.origin; CGFloat width = _faceView.frame.size.width; CGFloat height = _faceView.frame.size.height; CGFloat border = 2.0f; CGPoint startPt = CGPointMake(origin.x + width/2, self.frame.size.height); CGContextBeginPath(ctx); CGContextMoveToPoint(ctx, startPt.x, startPt.y); CGPoint basePt […]

Converting a NSString to a cString for use with CGContextShowTextAtPoint

I am drawing a String using CGContextShowTextAtPoint. Thus I need to convert my NSString I want to draw into c Strings. Unfortunately special symbols like the euro currency symbol are not correctly shown. CGContextSelectFont(currentContext, “TrebuchetMS”, 15, kCGEncodingMacRoman); CGContextShowTextAtPoint(currentContext, 0, 0, [myString cStringUsingEncoding:[NSString defaultCStringEncoding]], [myString length]); I tried it with the kCGEncodingFontSpecific encoding in the CGContextSelectFont […]

iOS CoreGraphics: Draw arc, determine arc angles from intersecting chord theorem

I’m trying to figure out how to draw an arc in CoreGraphics. I understand which method calls to make and how to compute the angles in the following scenario. ———- | | *——–* When the points are both in the bottom of the rect. However when two points are in other locations, I don’t know […]