CGContextDrawImage draws image upside down when passed UIImage.CGImage

Instead of CGContextDrawImage(context, CGRectMake(0, 0, 145, 15), image.CGImage); Use [image drawInRect:CGRectMake(0, 0, 145, 15)]; In the middle of your begin/end CGcontext methods. This will draw the image with the correct orientation into your current image context – I’m pretty sure this has something to do with the UIImage holding onto knowledge of the orientation while … 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

How do I make UILabel display outlined text?

I was able to do it by overriding drawTextInRect: – (void)drawTextInRect:(CGRect)rect { CGSize shadowOffset = self.shadowOffset; UIColor *textColor = self.textColor; CGContextRef c = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(c, 1); CGContextSetLineJoin(c, kCGLineJoinRound); CGContextSetTextDrawingMode(c, kCGTextStroke); self.textColor = [UIColor whiteColor]; [super drawTextInRect:rect]; CGContextSetTextDrawingMode(c, kCGTextFill); self.textColor = textColor; self.shadowOffset = CGSizeMake(0, 0); [super drawTextInRect:rect]; self.shadowOffset = shadowOffset; }

Inner shadow effect on UIView layer?

For anyone else wondering how to draw an inner shadow using Core Graphics as per Costique’s suggestion, then this is how: (on iOS adjust as needed) In your drawRect: method… CGRect bounds = [self bounds]; CGContextRef context = UIGraphicsGetCurrentContext(); CGFloat radius = 0.5f * CGRectGetHeight(bounds); // Create the “visible” path, which will be the shape … Read more

How to scale down a UIImage and make it crispy / sharp at the same time instead of blurry?

Merely using imageWithCGImage is not sufficient. It will scale, but the result will be blurry and suboptimal whether scaling up or down. If you want to get the aliasing right and get rid of the “jaggies” you need something like this: http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/. My working test code looks something like this, which is Trevor’s solution with … Read more