├── LICENSE ├── README.md ├── UIImage+RTTint.h ├── UIImage+RTTint.m └── UIImage+RTTint.podspec /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Ramon Torres 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UIImage+RTTint 2 | 3 | Retina-aware category for tinting, darkening and lightening a UIImage. 4 | 5 | ## Usage 6 | 7 | #import "UIImage+RTTint.h" 8 | ... 9 | UIImage *image = [UIImage imageNamed:@"Logo.png"]; 10 | UIImage *tinted = [image rt_tintedImageWithColor:[UIColor redColor] level:0.5f]; 11 | 12 | See [UIImage+RTTint.h](UIImage+RTTint.h) for more. 13 | 14 | ## Copyright 15 | 16 | Copyright © 2013 Ramon Torres. Released under the MIT License. 17 | -------------------------------------------------------------------------------- /UIImage+RTTint.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+RTTint.h 3 | // 4 | // Created by Ramon Torres on 7/3/13. 5 | // Copyright (c) 2013 Ramon Torres . All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface UIImage (RTTint) 11 | 12 | -(UIImage*)rt_tintedImageWithColor:(UIColor*)color; 13 | -(UIImage*)rt_tintedImageWithColor:(UIColor*)color level:(CGFloat)level; 14 | -(UIImage*)rt_tintedImageWithColor:(UIColor*)color rect:(CGRect)rect; 15 | -(UIImage*)rt_tintedImageWithColor:(UIColor*)color rect:(CGRect)rect level:(CGFloat)level; 16 | -(UIImage*)rt_tintedImageWithColor:(UIColor*)color insets:(UIEdgeInsets)insets; 17 | -(UIImage*)rt_tintedImageWithColor:(UIColor*)color insets:(UIEdgeInsets)insets level:(CGFloat)level; 18 | 19 | -(UIImage*)rt_lightenWithLevel:(CGFloat)level; 20 | -(UIImage*)rt_lightenWithLevel:(CGFloat)level insets:(UIEdgeInsets)insets; 21 | -(UIImage*)rt_lightenRect:(CGRect)rect withLevel:(CGFloat)level; 22 | 23 | -(UIImage*)rt_darkenWithLevel:(CGFloat)level; 24 | -(UIImage*)rt_darkenWithLevel:(CGFloat)level insets:(UIEdgeInsets)insets; 25 | -(UIImage*)rt_darkenRect:(CGRect)rect withLevel:(CGFloat)level; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /UIImage+RTTint.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+RTTint.m 3 | // 4 | // Created by Ramon Torres on 7/3/13. 5 | // Copyright (c) 2013 Ramon Torres . All rights reserved. 6 | // 7 | 8 | #import "UIImage+RTTint.h" 9 | 10 | @implementation UIImage (RTTint) 11 | 12 | // Tint: Color 13 | -(UIImage*)rt_tintedImageWithColor:(UIColor*)color { 14 | return [self rt_tintedImageWithColor:color level:1.0f]; 15 | } 16 | 17 | // Tint: Color + level 18 | -(UIImage*)rt_tintedImageWithColor:(UIColor*)color level:(CGFloat)level { 19 | CGRect rect = CGRectMake(0.0f, 0.0f, self.size.width, self.size.height); 20 | return [self rt_tintedImageWithColor:color rect:rect level:level]; 21 | } 22 | 23 | // Tint: Color + Rect 24 | -(UIImage*)rt_tintedImageWithColor:(UIColor*)color rect:(CGRect)rect { 25 | return [self rt_tintedImageWithColor:color rect:rect level:1.0f]; 26 | } 27 | 28 | // Tint: Color + Rect + level 29 | -(UIImage*)rt_tintedImageWithColor:(UIColor*)color rect:(CGRect)rect level:(CGFloat)level { 30 | CGRect imageRect = CGRectMake(0.0f, 0.0f, self.size.width, self.size.height); 31 | 32 | UIGraphicsBeginImageContextWithOptions(imageRect.size, NO, self.scale); 33 | CGContextRef ctx = UIGraphicsGetCurrentContext(); 34 | 35 | [self drawInRect:imageRect]; 36 | 37 | CGContextSetFillColorWithColor(ctx, [color CGColor]); 38 | CGContextSetAlpha(ctx, level); 39 | CGContextSetBlendMode(ctx, kCGBlendModeSourceAtop); 40 | CGContextFillRect(ctx, rect); 41 | 42 | CGImageRef imageRef = CGBitmapContextCreateImage(ctx); 43 | UIImage *darkImage = [UIImage imageWithCGImage:imageRef 44 | scale:self.scale 45 | orientation:self.imageOrientation]; 46 | CGImageRelease(imageRef); 47 | 48 | UIGraphicsEndImageContext(); 49 | 50 | return darkImage; 51 | } 52 | 53 | // Tint: Color + Insets 54 | -(UIImage*)rt_tintedImageWithColor:(UIColor*)color insets:(UIEdgeInsets)insets { 55 | return [self rt_tintedImageWithColor:color insets:insets level:1.0f]; 56 | } 57 | 58 | // Tint: Color + Insets + level 59 | -(UIImage*)rt_tintedImageWithColor:(UIColor*)color insets:(UIEdgeInsets)insets level:(CGFloat)level { 60 | CGRect rect = CGRectMake(0.0f, 0.0f, self.size.width, self.size.height); 61 | return [self rt_tintedImageWithColor:color rect:UIEdgeInsetsInsetRect(rect, insets) level:level]; 62 | } 63 | 64 | // Light: Level 65 | -(UIImage*)rt_lightenWithLevel:(CGFloat)level { 66 | return [self rt_tintedImageWithColor:[UIColor whiteColor] level:level]; 67 | } 68 | 69 | // Light: Level + Insets 70 | -(UIImage*)rt_lightenWithLevel:(CGFloat)level insets:(UIEdgeInsets)insets { 71 | return [self rt_tintedImageWithColor:[UIColor whiteColor] insets:insets level:level]; 72 | } 73 | 74 | // Light: Level + Rect 75 | -(UIImage*)rt_lightenRect:(CGRect)rect withLevel:(CGFloat)level { 76 | return [self rt_tintedImageWithColor:[UIColor whiteColor] rect:rect level:level]; 77 | } 78 | 79 | // Dark: Level 80 | -(UIImage*)rt_darkenWithLevel:(CGFloat)level { 81 | return [self rt_tintedImageWithColor:[UIColor blackColor] level:level]; 82 | } 83 | 84 | // Dark: Level + Insets 85 | -(UIImage*)rt_darkenWithLevel:(CGFloat)level insets:(UIEdgeInsets)insets { 86 | return [self rt_tintedImageWithColor:[UIColor blackColor] insets:insets level:level]; 87 | } 88 | 89 | // Dark: Level + Rect 90 | -(UIImage*)rt_darkenRect:(CGRect)rect withLevel:(CGFloat)level { 91 | return [self rt_tintedImageWithColor:[UIColor blackColor] rect:rect level:level]; 92 | } 93 | 94 | @end 95 | -------------------------------------------------------------------------------- /UIImage+RTTint.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'UIImage+RTTint' 3 | s.version = '1.0.0' 4 | s.authors = {'Ramon Torres' => 'raymondjavaxx@gmail.com'} 5 | s.homepage = 'https://github.com/raymondjavaxx/UIImage-RTTint' 6 | s.summary = 'Retina-aware category for tinting, darkening and lightening a UIImage.' 7 | s.source = {:git => 'https://github.com/raymondjavaxx/UIImage-RTTint.git', :tag => '1.0.0'} 8 | s.license = {:type => 'MIT', :file => 'LICENSE'} 9 | s.platform = :ios, '6.0' 10 | s.source_files = 'UIImage+RTTint.{m,h}' 11 | end --------------------------------------------------------------------------------