2 things i want to do, which are related:
Any ideas?
This time it's pretty simple. Just give the image element a background color and on hover change the image's opacity so the background color shows through, giving the appearance of an image tint.
To apply a color tint to an image, upload your photo or drag n drop it to the editor. Next, click on the ‘Image Effects & Filters’ button located at the top toolbar of the editor. Scroll down and select the ‘Tint Image’ tool. Adjust the color of the tint and its intensity using the slider.
To change image color, upload your photo or drag n drop it to the editor. Next, click on the ‘Image Effects & Filters’ button located at the top toolbar of the editor. Scroll down and select the tint tool. Adjust the color of the image and its intensity using the slider.
With the color swatch created, you can apply that color to other artwork and then create a tint, or lighter version, of the color. Apply the swatch you created to the fill or stroke of artwork. Click the Fill color or Stroke color in the Properties panel and click the Color Mixer option at the top of the panel to show a single tint (T) slider.
Tutorials: Animated TextSwapping FacesChange Eye ColorAnimated WinkPost Animations on FacebookReplace Sky with SunsetPositive ReviewsRemove ObjectsRotated TextChange Background LunaPic> Filters> Color Tint Upload your photo for tint or, open URL Use Lunapic to Tint your Image! Use form above to pick an image file or URL
Another option, would be to use category methods on UIImage like this...
// Tint the image, default to half transparency if given an opaque colour.
- (UIImage *)imageWithTint:(UIColor *)tintColor {
CGFloat white, alpha;
[tintColor getWhite:&white alpha:&alpha];
return [self imageWithTint:tintColor alpha:(alpha == 1.0 ? 0.5f : alpha)];
}
// Tint the image
- (UIImage *)imageWithTint:(UIColor *)tintColor alpha:(CGFloat)alpha {
// Begin drawing
CGRect aRect = CGRectMake(0.f, 0.f, self.size.width, self.size.height);
UIGraphicsBeginImageContext(aRect.size);
// Get the graphic context
CGContextRef c = UIGraphicsGetCurrentContext();
// Converting a UIImage to a CGImage flips the image,
// so apply a upside-down translation
CGContextTranslateCTM(c, 0, self.size.height);
CGContextScaleCTM(c, 1.0, -1.0);
// Draw the image
[self drawInRect:aRect];
// Set the fill color space
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextSetFillColorSpace(c, colorSpace);
// Set the mask to only tint non-transparent pixels
CGContextClipToMask(c, aRect, self.CGImage);
// Set the fill color
CGContextSetFillColorWithColor(c, [tintColor colorWithAlphaComponent:alpha].CGColor);
UIRectFillUsingBlendMode(aRect, kCGBlendModeColor);
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Release memory
CGColorSpaceRelease(colorSpace);
return img;
}
The first one is easy. Make a new UIView
and set its background color to whatever color you’d like.
The second is more difficult. As you mentioned, you can put a new view on top of it with transparency turned down, but to get it to clip in the same places, you’d want to use a mask. Something like this:
UIImage *myImage = [UIImage imageNamed:@"foo.png"];
UIImageView *originalImageView = [[UIImageView alloc] initWithImage:myImage];
[originalImageView setFrame:CGRectMake(0.0f, 0.0f, 100.0f, 100.0f)];
[parentView addSubview:originalImageView];
UIView *overlay = [[UIView alloc] initWithFrame:[originalImageView frame]];
UIImageView *maskImageView = [[UIImageView alloc] initWithImage:myImage];
[maskImageView setFrame:[overlay bounds]];
[[overlay layer] setMask:[maskImageView layer]];
[overlay setBackgroundColor:[UIColor redColor]];
[parentView addSubview:overlay];
Keep in mind you’ll have to #import <QuartzCore/QuartzCore.h>
in the implementation file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With