How to compensate the flipped coordinate system of core graphics for easy drawing?

Problem: Origin is at lower-left corner; positive y goes upward (negative y goes downward). Goal: Origin at upper-left corner; positive y going downward (negative y going upward). Solution: Move origin up by the view’s height. Negate (multiply by -1) the y axis. The way to do this in code is to translate up by the … Read more

Can’t add a corner radius and a shadow

Yes, yes there is… If you want both a corner radius and a drop shadow, you don’t turn on -masksToBounds, but rather set the corner radius and set the bezier path of the shadow with a rounded rect. Keep the radius of the two the same: [layer setShadowOffset:CGSizeMake(0, 3)]; [layer setShadowOpacity:0.4]; [layer setShadowRadius:3.0f]; [layer setShouldRasterize:YES]; … Read more

CAKeyframeAnimation delay before repeating

By dumping the animations of Apple’s MKUserLocationView, I was able to see how they were doing it. Turns out that this is what CAAnimationGroup is for. By encapsulating a 2 seconds animation into a 5 seconds animation group, you’ll end up with a 2 seconds animation followed by a 3 seconds delay: CAAnimationGroup *animationGroup = … Read more

Applying a Gradient to CAShapeLayer

You could use the path of your shape to create a masking layer and apply that on the gradient layer, like this: UIView *v = [[UIView alloc] initWithFrame:self.window.frame]; CAShapeLayer *gradientMask = [CAShapeLayer layer]; gradientMask.fillColor = [[UIColor clearColor] CGColor]; gradientMask.strokeColor = [[UIColor blackColor] CGColor]; gradientMask.lineWidth = 4; gradientMask.frame = CGRectMake(0, 0, v.bounds.size.width, v.bounds.size.height); CGMutablePathRef t = … Read more

Resize UIImage with aspect ratio?

After you set your screen rect, do something like the following to decide what rect to draw the image in: float hfactor = value.bounds.size.width / screenRect.size.width; float vfactor = value.bounds.size.height / screenRect.size.height; float factor = fmax(hfactor, vfactor); // Divide the size by the greater of the vertical or horizontal shrinkage factor float newWidth = value.bounds.size.width … Read more

Vertical flip of CGContext

Here is some code that I wrote based on this answer, in case it is helpful to anyone: #import <QuartzCore/QuartzCore.h> … + (UIImage *) flipImageVertically:(UIImage *)originalImage { UIImageView *tempImageView = [[UIImageView alloc] initWithImage:originalImage]; UIGraphicsBeginImageContext(tempImageView.frame.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGAffineTransform flipVertical = CGAffineTransformMake( 1, 0, 0, -1, 0, tempImageView.frame.size.height ); CGContextConcatCTM(context, flipVertical); [tempImageView.layer renderInContext:context]; UIImage *flipedImage … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)