How can I tint a UIImage with gradient?

EDIT: Here is a version which supports non-retina and retina displays The method can be used as a category for UIImage + (UIImage *)imageWithGradient:(UIImage *)img startColor:(UIColor *)color1 endColor:(UIColor *)color2 { UIGraphicsBeginImageContextWithOptions(img.size, NO, img.scale); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextTranslateCTM(context, 0, img.size.height); CGContextScaleCTM(context, 1.0, -1.0); CGContextSetBlendMode(context, kCGBlendModeNormal); CGRect rect = CGRectMake(0, 0, img.size.width, img.size.height); //CGContextDrawImage(context, rect, img.CGImage); … Read more

Most efficient way to draw part of an image in iOS

I guessed you are doing this to display part of an image on the screen, because you mentioned UIImageView. And optimization problems always need defining specifically. Trust Apple for Regular UI stuff Actually, UIImageView with clipsToBounds is one of the fastest/simplest ways to archive your goal if your goal is just clipping a rectangular region … Read more

drawRect on top of subviews

A subview will always be drawn on “top” of its superview. Depending on your specific requirements, you may need to have a plain UIView as the background/container view, with your existing subviews in there, and then your custom view as another subview added to the very top, so it has the highest Z-order. This would … Read more

How to fill a path with gradient in drawRect:?

I would clip to the path you want to fill, and use CGContextDrawLinearGradient. Here is a simple implementation of drawRect: as an example: – (void) drawRect:(CGRect)rect { // Create a gradient from white to red CGFloat colors [] = { 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0 }; CGColorSpaceRef baseSpace = CGColorSpaceCreateDeviceRGB(); CGGradientRef gradient … Read more

UIView with shadow, rounded corners and custom drawRect

This is a tricky one. UIView‘s clipsToBounds is necessary to get the rounded corners. But CALayer‘s masksToBounds has to be false so the shadow is visible. Somehow, everything works if drawRect is not overridden, but actually it shouldn’t. The solution is to create a superview to provide the shadow (in the demonstration below this is … Read more

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