diff --git a/RZUtils/Categories/UIImage/UIImage+RZTint.h b/RZUtils/Categories/UIImage/UIImage+RZTint.h new file mode 100644 index 0000000..2cc4085 --- /dev/null +++ b/RZUtils/Categories/UIImage/UIImage+RZTint.h @@ -0,0 +1,42 @@ +// +// UIImage+RZTint.h +// +// Created by Zev Eisenberg on 5/11/15. + +// Copyright 2015 Raizlabs and other contributors +// http://raizlabs.com/ +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +#import + +@interface UIImage (RZTint) + +/** + * Tints an image with the provided color. Preserves the original image’s alignment rect insets, cap insets, and resizing mode. + * + * @param color The color to tint the image. Must not be @c nil. + * + * @return A tinted version of the image. + */ +- (UIImage *)rz_tintedImageWithColor:(UIColor *)color; + +@end diff --git a/RZUtils/Categories/UIImage/UIImage+RZTint.m b/RZUtils/Categories/UIImage/UIImage+RZTint.m new file mode 100644 index 0000000..c550a14 --- /dev/null +++ b/RZUtils/Categories/UIImage/UIImage+RZTint.m @@ -0,0 +1,75 @@ +// +// UIImage+RZTint.m +// +// Created by Zev Eisenberg on 5/11/15. + +#import "UIImage+RZTint.h" + +// Copyright 2015 Raizlabs and other contributors +// http://raizlabs.com/ +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +@implementation UIImage (RZTint) + +- (UIImage *)rz_tintedImageWithColor:(UIColor *)color +{ + NSParameterAssert(color); + + // Save original properties + UIEdgeInsets originalCapInsets = self.capInsets; + UIImageResizingMode originalResizingMode = self.resizingMode; + UIEdgeInsets originalAlignmentRectInsets = self.alignmentRectInsets; + + // Create image context + UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0f); + CGContextRef ctx = UIGraphicsGetCurrentContext(); + + // Flip the context vertically + CGContextTranslateCTM(ctx, 0.0f, self.size.height); + CGContextScaleCTM(ctx, 1.0f, -1.0f); + + CGRect imageRect = CGRectMake(0.0f, 0.0f, self.size.width, self.size.height); + + // Image tinting mostly inspired by http://stackoverflow.com/a/22528426/255489 + + CGContextSetBlendMode(ctx, kCGBlendModeNormal); + CGContextDrawImage(ctx, imageRect, self.CGImage); + + // kCGBlendModeSourceIn: resulting color = source color * destination alpha + CGContextSetBlendMode(ctx, kCGBlendModeSourceIn); + CGContextSetFillColorWithColor(ctx, color.CGColor); + CGContextFillRect(ctx, imageRect); + + // Get new image + UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + + // Restore original properties + image = [image imageWithAlignmentRectInsets:originalAlignmentRectInsets]; + if ( !UIEdgeInsetsEqualToEdgeInsets(originalCapInsets, image.capInsets) || originalResizingMode != image.resizingMode ) { + image = [image resizableImageWithCapInsets:originalCapInsets resizingMode:originalResizingMode]; + } + + return image; +} + +@end diff --git a/Tests/Default-568h@2x.png b/Tests/Default-568h@2x.png new file mode 100644 index 0000000..0891b7a Binary files /dev/null and b/Tests/Default-568h@2x.png differ diff --git a/Tests/RZHostApp/AppDelegate.h b/Tests/RZHostApp/AppDelegate.h new file mode 100644 index 0000000..9962316 --- /dev/null +++ b/Tests/RZHostApp/AppDelegate.h @@ -0,0 +1,17 @@ +// +// AppDelegate.h +// RZHostApp +// +// Created by Zev Eisenberg on 5/11/15. +// Copyright (c) 2015 Raizlabs. All rights reserved. +// + +#import + +@interface AppDelegate : UIResponder + +@property (strong, nonatomic) UIWindow *window; + + +@end + diff --git a/Tests/RZHostApp/AppDelegate.m b/Tests/RZHostApp/AppDelegate.m new file mode 100644 index 0000000..6c018f1 --- /dev/null +++ b/Tests/RZHostApp/AppDelegate.m @@ -0,0 +1,23 @@ +// +// AppDelegate.m +// RZHostApp +// +// Created by Zev Eisenberg on 5/11/15. +// Copyright (c) 2015 Raizlabs. All rights reserved. +// + +#import "AppDelegate.h" + +@interface AppDelegate () + +@end + +@implementation AppDelegate + + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + // Override point for customization after application launch. + return YES; +} + +@end diff --git a/Tests/RZHostApp/Base.lproj/LaunchScreen.xib b/Tests/RZHostApp/Base.lproj/LaunchScreen.xib new file mode 100644 index 0000000..5d6ddb3 --- /dev/null +++ b/Tests/RZHostApp/Base.lproj/LaunchScreen.xib @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/RZHostApp/Info.plist b/Tests/RZHostApp/Info.plist new file mode 100644 index 0000000..3bd02fd --- /dev/null +++ b/Tests/RZHostApp/Info.plist @@ -0,0 +1,43 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + com.raizlabs.$(PRODUCT_NAME:rfc1034identifier) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/Tests/RZHostApp/main.m b/Tests/RZHostApp/main.m new file mode 100644 index 0000000..7548d58 --- /dev/null +++ b/Tests/RZHostApp/main.m @@ -0,0 +1,16 @@ +// +// main.m +// RZHostApp +// +// Created by Zev Eisenberg on 5/11/15. +// Copyright (c) 2015 Raizlabs. All rights reserved. +// + +#import +#import "AppDelegate.h" + +int main(int argc, char * argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } +} diff --git a/Tests/RZUtilsTests.xcodeproj/project.pbxproj b/Tests/RZUtilsTests.xcodeproj/project.pbxproj index 6ec8de0..6bfeeec 100644 --- a/Tests/RZUtilsTests.xcodeproj/project.pbxproj +++ b/Tests/RZUtilsTests.xcodeproj/project.pbxproj @@ -7,16 +7,35 @@ objects = { /* Begin PBXBuildFile section */ + 364C0F78348087AEC2889C42 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 22BAB0697B95400AAAD3740C /* libPods.a */; }; 7A175505AE684DAFB8613F72 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 22BAB0697B95400AAAD3740C /* libPods.a */; }; 9A8D4DF4196335CC00AFAB21 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9A8D4DF3196335CC00AFAB21 /* XCTest.framework */; }; 9A8D4DF5196335CC00AFAB21 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9A8D4DD1196335CC00AFAB21 /* Foundation.framework */; }; 9A8D4DF6196335CC00AFAB21 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9A8D4DD5196335CC00AFAB21 /* UIKit.framework */; }; 9A8D4DFE196335CC00AFAB21 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 9A8D4DFC196335CC00AFAB21 /* InfoPlist.strings */; }; 9A8D4EB61963431900AFAB21 /* RZBlockKVOTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A8D4EB51963431900AFAB21 /* RZBlockKVOTests.m */; }; + CD475B311B018D66000C0C8A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = CD475B301B018D66000C0C8A /* main.m */; }; + CD475B341B018D66000C0C8A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = CD475B331B018D66000C0C8A /* AppDelegate.m */; }; + CD475B3F1B018D66000C0C8A /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = CD475B3D1B018D66000C0C8A /* LaunchScreen.xib */; }; + CD475B561B018D9D000C0C8A /* Test Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CDDB47901B018B1D0012A201 /* Test Images.xcassets */; }; + CDDB478F1B0189B80012A201 /* RZImageTintTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CDDB478E1B0189B80012A201 /* RZImageTintTests.m */; }; + CDDB47911B018B1D0012A201 /* Test Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CDDB47901B018B1D0012A201 /* Test Images.xcassets */; }; + CDFA4DBD1B018E7A00918E27 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = CDFA4DBC1B018E7A00918E27 /* Default-568h@2x.png */; }; D4874DA119918C46003EEC4B /* RZAutoLayoutTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D4874DA019918C46003EEC4B /* RZAutoLayoutTests.m */; }; /* End PBXBuildFile section */ +/* Begin PBXContainerItemProxy section */ + CD475B541B018D71000C0C8A /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 9A8D4DC6196335CC00AFAB21 /* Project object */; + proxyType = 1; + remoteGlobalIDString = CD475B2B1B018D66000C0C8A; + remoteInfo = RZHostApp; + }; +/* End PBXContainerItemProxy section */ + /* Begin PBXFileReference section */ + 19428E876E28110F46DB30FA /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = ""; }; 22BAB0697B95400AAAD3740C /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; 9A8D4DD1196335CC00AFAB21 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 9A8D4DD3196335CC00AFAB21 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; @@ -26,9 +45,18 @@ 9A8D4DF3196335CC00AFAB21 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 9A8D4DFB196335CC00AFAB21 /* RZUtilsTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "RZUtilsTests-Info.plist"; sourceTree = ""; }; 9A8D4DFD196335CC00AFAB21 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; - 9A8D4EB4196336C500AFAB21 /* RZUtilsTests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RZUtilsTests-Prefix.pch"; sourceTree = ""; }; 9A8D4EB51963431900AFAB21 /* RZBlockKVOTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RZBlockKVOTests.m; sourceTree = ""; }; - CFC331EF976D4DEC8CB9094C /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = ""; }; + AA43025CFD9319FD22B5CA8F /* Pods.enterprise-qa.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods.enterprise-qa.xcconfig"; path = "Pods/Target Support Files/Pods/Pods.enterprise-qa.xcconfig"; sourceTree = ""; }; + CAE27EC2D5A3F04FF06102A4 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = ""; }; + CD475B2C1B018D66000C0C8A /* RZHostApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RZHostApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; + CD475B2F1B018D66000C0C8A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + CD475B301B018D66000C0C8A /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + CD475B321B018D66000C0C8A /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + CD475B331B018D66000C0C8A /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + CD475B3E1B018D66000C0C8A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; + CDDB478E1B0189B80012A201 /* RZImageTintTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RZImageTintTests.m; sourceTree = ""; }; + CDDB47901B018B1D0012A201 /* Test Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Test Images.xcassets"; sourceTree = ""; }; + CDFA4DBC1B018E7A00918E27 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = ""; }; D4874DA019918C46003EEC4B /* RZAutoLayoutTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RZAutoLayoutTests.m; sourceTree = ""; }; /* End PBXFileReference section */ @@ -44,16 +72,26 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + CD475B291B018D66000C0C8A /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 364C0F78348087AEC2889C42 /* libPods.a in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ 9A8D4DC5196335CC00AFAB21 = { isa = PBXGroup; children = ( + CDFA4DBC1B018E7A00918E27 /* Default-568h@2x.png */, 9A8D4DF9196335CC00AFAB21 /* RZUtilsTests */, + CD475B2D1B018D66000C0C8A /* RZHostApp */, 9A8D4DD0196335CC00AFAB21 /* Frameworks */, 9A8D4DCF196335CC00AFAB21 /* Products */, - CFC331EF976D4DEC8CB9094C /* Pods.xcconfig */, + BDE41AA10EFDC1CC3F7E3386 /* Pods */, ); sourceTree = ""; }; @@ -61,6 +99,7 @@ isa = PBXGroup; children = ( 9A8D4DF2196335CC00AFAB21 /* RZUtilsTests.xctest */, + CD475B2C1B018D66000C0C8A /* RZHostApp.app */, ); name = Products; sourceTree = ""; @@ -82,8 +121,9 @@ isa = PBXGroup; children = ( 9A8D4DFA196335CC00AFAB21 /* Supporting Files */, - 9A8D4EB51963431900AFAB21 /* RZBlockKVOTests.m */, D4874DA019918C46003EEC4B /* RZAutoLayoutTests.m */, + 9A8D4EB51963431900AFAB21 /* RZBlockKVOTests.m */, + CDDB478E1B0189B80012A201 /* RZImageTintTests.m */, ); path = RZUtilsTests; sourceTree = ""; @@ -93,11 +133,41 @@ children = ( 9A8D4DFB196335CC00AFAB21 /* RZUtilsTests-Info.plist */, 9A8D4DFC196335CC00AFAB21 /* InfoPlist.strings */, - 9A8D4EB4196336C500AFAB21 /* RZUtilsTests-Prefix.pch */, + CDDB47901B018B1D0012A201 /* Test Images.xcassets */, ); path = "Supporting Files"; sourceTree = ""; }; + BDE41AA10EFDC1CC3F7E3386 /* Pods */ = { + isa = PBXGroup; + children = ( + CAE27EC2D5A3F04FF06102A4 /* Pods.debug.xcconfig */, + 19428E876E28110F46DB30FA /* Pods.release.xcconfig */, + AA43025CFD9319FD22B5CA8F /* Pods.enterprise-qa.xcconfig */, + ); + name = Pods; + sourceTree = ""; + }; + CD475B2D1B018D66000C0C8A /* RZHostApp */ = { + isa = PBXGroup; + children = ( + CD475B321B018D66000C0C8A /* AppDelegate.h */, + CD475B331B018D66000C0C8A /* AppDelegate.m */, + CD475B3D1B018D66000C0C8A /* LaunchScreen.xib */, + CD475B2E1B018D66000C0C8A /* Supporting Files */, + ); + path = RZHostApp; + sourceTree = ""; + }; + CD475B2E1B018D66000C0C8A /* Supporting Files */ = { + isa = PBXGroup; + children = ( + CD475B2F1B018D66000C0C8A /* Info.plist */, + CD475B301B018D66000C0C8A /* main.m */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -114,12 +184,32 @@ buildRules = ( ); dependencies = ( + CD475B551B018D71000C0C8A /* PBXTargetDependency */, ); name = RZUtilsTests; productName = RZUtilsTests; productReference = 9A8D4DF2196335CC00AFAB21 /* RZUtilsTests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; + CD475B2B1B018D66000C0C8A /* RZHostApp */ = { + isa = PBXNativeTarget; + buildConfigurationList = CD475B521B018D66000C0C8A /* Build configuration list for PBXNativeTarget "RZHostApp" */; + buildPhases = ( + FC3B370C76E1787C3C557EAC /* Check Pods Manifest.lock */, + CD475B281B018D66000C0C8A /* Sources */, + CD475B291B018D66000C0C8A /* Frameworks */, + CD475B2A1B018D66000C0C8A /* Resources */, + 16C5AB32AB697CDBC193F861 /* Copy Pods Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = RZHostApp; + productName = RZHostApp; + productReference = CD475B2C1B018D66000C0C8A /* RZHostApp.app */; + productType = "com.apple.product-type.application"; + }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ @@ -127,8 +217,16 @@ isa = PBXProject; attributes = { CLASSPREFIX = RZ; - LastUpgradeCheck = 0510; + LastUpgradeCheck = 0630; ORGANIZATIONNAME = Raizlabs; + TargetAttributes = { + 9A8D4DF1196335CC00AFAB21 = { + TestTargetID = CD475B2B1B018D66000C0C8A; + }; + CD475B2B1B018D66000C0C8A = { + CreatedOnToolsVersion = 6.3.1; + }; + }; }; buildConfigurationList = 9A8D4DC9196335CC00AFAB21 /* Build configuration list for PBXProject "RZUtilsTests" */; compatibilityVersion = "Xcode 3.2"; @@ -136,12 +234,14 @@ hasScannedForEncodings = 0; knownRegions = ( en, + Base, ); mainGroup = 9A8D4DC5196335CC00AFAB21; productRefGroup = 9A8D4DCF196335CC00AFAB21 /* Products */; projectDirPath = ""; projectRoot = ""; targets = ( + CD475B2B1B018D66000C0C8A /* RZHostApp */, 9A8D4DF1196335CC00AFAB21 /* RZUtilsTests */, ); }; @@ -152,13 +252,39 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + CDDB47911B018B1D0012A201 /* Test Images.xcassets in Resources */, 9A8D4DFE196335CC00AFAB21 /* InfoPlist.strings in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; + CD475B2A1B018D66000C0C8A /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + CD475B3F1B018D66000C0C8A /* LaunchScreen.xib in Resources */, + CD475B561B018D9D000C0C8A /* Test Images.xcassets in Resources */, + CDFA4DBD1B018E7A00918E27 /* Default-568h@2x.png in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ + 16C5AB32AB697CDBC193F861 /* Copy Pods Resources */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Copy Pods Resources"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods/Pods-resources.sh\"\n"; + showEnvVarsInLog = 0; + }; DB328C2D17B7432F9AFBFA98 /* Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -171,7 +297,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Pods-resources.sh\"\n"; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods/Pods-resources.sh\"\n"; showEnvVarsInLog = 0; }; DFCEA1E42D714A99949F834D /* Check Pods Manifest.lock */ = { @@ -189,6 +315,21 @@ shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; + FC3B370C76E1787C3C557EAC /* Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Check Pods Manifest.lock"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; + showEnvVarsInLog = 0; + }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -198,11 +339,29 @@ files = ( D4874DA119918C46003EEC4B /* RZAutoLayoutTests.m in Sources */, 9A8D4EB61963431900AFAB21 /* RZBlockKVOTests.m in Sources */, + CDDB478F1B0189B80012A201 /* RZImageTintTests.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + CD475B281B018D66000C0C8A /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + CD475B341B018D66000C0C8A /* AppDelegate.m in Sources */, + CD475B311B018D66000C0C8A /* main.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ +/* Begin PBXTargetDependency section */ + CD475B551B018D71000C0C8A /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = CD475B2B1B018D66000C0C8A /* RZHostApp */; + targetProxy = CD475B541B018D71000C0C8A /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + /* Begin PBXVariantGroup section */ 9A8D4DFC196335CC00AFAB21 /* InfoPlist.strings */ = { isa = PBXVariantGroup; @@ -212,6 +371,14 @@ name = InfoPlist.strings; sourceTree = ""; }; + CD475B3D1B018D66000C0C8A /* LaunchScreen.xib */ = { + isa = PBXVariantGroup; + children = ( + CD475B3E1B018D66000C0C8A /* Base */, + ); + name = LaunchScreen.xib; + sourceTree = ""; + }; /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ @@ -219,7 +386,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -258,7 +424,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -291,7 +456,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -327,15 +491,14 @@ }; 9A8D4E09196335CC00AFAB21 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = CFC331EF976D4DEC8CB9094C /* Pods.xcconfig */; + baseConfigurationReference = CAE27EC2D5A3F04FF06102A4 /* Pods.debug.xcconfig */; buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; FRAMEWORK_SEARCH_PATHS = ( "$(SDKROOT)/Developer/Library/Frameworks", "$(inherited)", "$(DEVELOPER_FRAMEWORKS_DIR)", ); - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = "RZUtilsTests/Supporting Files/RZUtilsTests-Prefix.pch"; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", @@ -343,46 +506,104 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; INFOPLIST_FILE = "RZUtilsTests/Supporting Files/RZUtilsTests-Info.plist"; PRODUCT_NAME = "$(TARGET_NAME)"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/RZHostApp.app/RZHostApp"; WRAPPER_EXTENSION = xctest; }; name = Debug; }; 9A8D4E0A196335CC00AFAB21 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = CFC331EF976D4DEC8CB9094C /* Pods.xcconfig */; + baseConfigurationReference = 19428E876E28110F46DB30FA /* Pods.release.xcconfig */; buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; FRAMEWORK_SEARCH_PATHS = ( "$(SDKROOT)/Developer/Library/Frameworks", "$(inherited)", "$(DEVELOPER_FRAMEWORKS_DIR)", ); - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = "RZUtilsTests/Supporting Files/RZUtilsTests-Prefix.pch"; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; INFOPLIST_FILE = "RZUtilsTests/Supporting Files/RZUtilsTests-Info.plist"; PRODUCT_NAME = "$(TARGET_NAME)"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/RZHostApp.app/RZHostApp"; WRAPPER_EXTENSION = xctest; }; name = Release; }; 9A8D4E0B196335CC00AFAB21 /* Enterprise-QA */ = { isa = XCBuildConfiguration; - baseConfigurationReference = CFC331EF976D4DEC8CB9094C /* Pods.xcconfig */; + baseConfigurationReference = AA43025CFD9319FD22B5CA8F /* Pods.enterprise-qa.xcconfig */; buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; FRAMEWORK_SEARCH_PATHS = ( "$(SDKROOT)/Developer/Library/Frameworks", "$(inherited)", "$(DEVELOPER_FRAMEWORKS_DIR)", ); - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = "RZUtilsTests/Supporting Files/RZUtilsTests-Prefix.pch"; GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; INFOPLIST_FILE = "RZUtilsTests/Supporting Files/RZUtilsTests-Info.plist"; PRODUCT_NAME = "$(TARGET_NAME)"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/RZHostApp.app/RZHostApp"; WRAPPER_EXTENSION = xctest; }; name = "Enterprise-QA"; }; + CD475B4C1B018D66000C0C8A /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = CAE27EC2D5A3F04FF06102A4 /* Pods.debug.xcconfig */; + buildSettings = { + CLANG_WARN_UNREACHABLE_CODE = YES; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_NO_COMMON_BLOCKS = YES; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + INFOPLIST_FILE = RZHostApp/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + MTL_ENABLE_DEBUG_INFO = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + CD475B4D1B018D66000C0C8A /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 19428E876E28110F46DB30FA /* Pods.release.xcconfig */; + buildSettings = { + CLANG_WARN_UNREACHABLE_CODE = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + INFOPLIST_FILE = RZHostApp/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + MTL_ENABLE_DEBUG_INFO = NO; + PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; + CD475B4E1B018D66000C0C8A /* Enterprise-QA */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = AA43025CFD9319FD22B5CA8F /* Pods.enterprise-qa.xcconfig */; + buildSettings = { + CLANG_WARN_UNREACHABLE_CODE = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + INFOPLIST_FILE = RZHostApp/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + MTL_ENABLE_DEBUG_INFO = NO; + PRODUCT_NAME = "$(TARGET_NAME)"; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = "Enterprise-QA"; + }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ @@ -406,6 +627,16 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + CD475B521B018D66000C0C8A /* Build configuration list for PBXNativeTarget "RZHostApp" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + CD475B4C1B018D66000C0C8A /* Debug */, + CD475B4D1B018D66000C0C8A /* Release */, + CD475B4E1B018D66000C0C8A /* Enterprise-QA */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; /* End XCConfigurationList section */ }; rootObject = 9A8D4DC6196335CC00AFAB21 /* Project object */; diff --git a/Tests/RZUtilsTests.xcodeproj/xcshareddata/xcschemes/RZUtilsTests.xcscheme b/Tests/RZUtilsTests.xcodeproj/xcshareddata/xcschemes/RZUtilsTests.xcscheme index b0389c1..55e6a48 100644 --- a/Tests/RZUtilsTests.xcodeproj/xcshareddata/xcschemes/RZUtilsTests.xcscheme +++ b/Tests/RZUtilsTests.xcodeproj/xcshareddata/xcschemes/RZUtilsTests.xcscheme @@ -1,6 +1,6 @@ - + - + +#import + +#import + +@interface RZImageTintTests : XCTestCase + +@property (strong, nonatomic) UIImage *testImage; + +@end + +@implementation RZImageTintTests + +- (void)setUp +{ + [super setUp]; + self.testImage = [UIImage imageNamed:@"Raizlabs Logo"]; +} + +- (void)testTinting +{ + XCTAssertNotNil(self.testImage); + + NSData *testData = UIImagePNGRepresentation(self.testImage); + + UIImage *blueImage1 = [self.testImage rz_tintedImageWithColor:[UIColor blueColor]]; + NSData *blueData1 = UIImagePNGRepresentation(blueImage1); + + XCTAssertNotEqualObjects(testData, blueData1, @"A tinted image should not be the same as the original, unless the original has changed since this test was written"); + + UIImage *redImage = [blueImage1 rz_tintedImageWithColor:[UIColor redColor]]; + NSData *redData = UIImagePNGRepresentation(redImage); + + XCTAssertNotEqualObjects(blueData1, redData, @"Two of the same image, tinted with different colors, should not be equal"); + + UIImage *blueImage2 = [redImage rz_tintedImageWithColor:[UIColor blueColor]]; + NSData *blueData2 = UIImagePNGRepresentation(blueImage2); + + XCTAssertEqualObjects(blueData1, blueData2, @"An image, tinted a different color and then tinted the original color again, should result in the same image"); +} + +- (void)testAttributes +{ + XCTAssertNotNil(self.testImage); + + UIEdgeInsets capInsets = UIEdgeInsetsMake(1.0f, 2.0f, 5.0f, 3.0f); + UIEdgeInsets alignmentRectInsets = UIEdgeInsetsMake(5.0f, 4.0f, 3.0f, 2.0f); + UIImageResizingMode resizingMode = UIImageResizingModeStretch; + UIImage *testImageWithAttributes = [self.testImage resizableImageWithCapInsets:capInsets resizingMode:resizingMode]; + testImageWithAttributes = [testImageWithAttributes imageWithAlignmentRectInsets:alignmentRectInsets]; + NSData *dataWithAttributes = UIImagePNGRepresentation(testImageWithAttributes); + + // first check assumptions about how these properties work + XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(capInsets, testImageWithAttributes.capInsets)); + XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(alignmentRectInsets, testImageWithAttributes.alignmentRectInsets)); + XCTAssertEqual(resizingMode, testImageWithAttributes.resizingMode); + + // make sure the attributes survive the tinting of the image + UIImage *tintedImage = [testImageWithAttributes rz_tintedImageWithColor:[UIColor purpleColor]]; + NSData *tintedData = UIImagePNGRepresentation(tintedImage); + XCTAssertNotEqualObjects(dataWithAttributes, tintedData); + + XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(capInsets, tintedImage.capInsets)); + XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(alignmentRectInsets, tintedImage.alignmentRectInsets)); + XCTAssertEqual(resizingMode, tintedImage.resizingMode); +} + +- (void)testNonOpaqueColor +{ + XCTAssertNotNil(self.testImage); + + NSData *testData = UIImagePNGRepresentation(self.testImage); + + UIImage *alphaTintedImage = [self.testImage rz_tintedImageWithColor:[[UIColor whiteColor] colorWithAlphaComponent:0.5f]]; + NSData *alphaTintedData = UIImagePNGRepresentation(alphaTintedImage); + XCTAssertNotEqualObjects(testData, alphaTintedData, @"An image tinted with a color whose alpha component is not 1 should be different from the original"); +} + +@end diff --git a/Tests/RZUtilsTests/Supporting Files/RZUtilsTests-Prefix.pch b/Tests/RZUtilsTests/Supporting Files/RZUtilsTests-Prefix.pch deleted file mode 100644 index fe3102f..0000000 --- a/Tests/RZUtilsTests/Supporting Files/RZUtilsTests-Prefix.pch +++ /dev/null @@ -1,18 +0,0 @@ -// -// RZUtilsTests-Prefix.pch -// RZUtilsTests -// -// Created by Nick Donaldson on 7/1/14. -// Copyright (c) 2014 Raizlabs. All rights reserved. -// - -#import - -#ifndef __IPHONE_6_0 - #warning "This project uses features only available in iOS SDK 6.0 and later." -#endif - -#ifdef __OBJC__ - #import - #import -#endif diff --git a/Tests/RZUtilsTests/Supporting Files/Raizalbs Logo.sketch b/Tests/RZUtilsTests/Supporting Files/Raizalbs Logo.sketch new file mode 100644 index 0000000..3c81111 Binary files /dev/null and b/Tests/RZUtilsTests/Supporting Files/Raizalbs Logo.sketch differ diff --git a/Tests/RZUtilsTests/Supporting Files/Test Images.xcassets/Raizlabs Logo.imageset/Contents.json b/Tests/RZUtilsTests/Supporting Files/Test Images.xcassets/Raizlabs Logo.imageset/Contents.json new file mode 100644 index 0000000..cd246ed --- /dev/null +++ b/Tests/RZUtilsTests/Supporting Files/Test Images.xcassets/Raizlabs Logo.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x", + "filename" : "Raizlabs Logo.png" + }, + { + "idiom" : "universal", + "scale" : "2x", + "filename" : "Raizlabs Logo@2x.png" + }, + { + "idiom" : "universal", + "scale" : "3x", + "filename" : "Raizlabs Logo@3x.png" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Tests/RZUtilsTests/Supporting Files/Test Images.xcassets/Raizlabs Logo.imageset/Raizlabs Logo.png b/Tests/RZUtilsTests/Supporting Files/Test Images.xcassets/Raizlabs Logo.imageset/Raizlabs Logo.png new file mode 100644 index 0000000..34762d0 Binary files /dev/null and b/Tests/RZUtilsTests/Supporting Files/Test Images.xcassets/Raizlabs Logo.imageset/Raizlabs Logo.png differ diff --git a/Tests/RZUtilsTests/Supporting Files/Test Images.xcassets/Raizlabs Logo.imageset/Raizlabs Logo@2x.png b/Tests/RZUtilsTests/Supporting Files/Test Images.xcassets/Raizlabs Logo.imageset/Raizlabs Logo@2x.png new file mode 100644 index 0000000..88bfab4 Binary files /dev/null and b/Tests/RZUtilsTests/Supporting Files/Test Images.xcassets/Raizlabs Logo.imageset/Raizlabs Logo@2x.png differ diff --git a/Tests/RZUtilsTests/Supporting Files/Test Images.xcassets/Raizlabs Logo.imageset/Raizlabs Logo@3x.png b/Tests/RZUtilsTests/Supporting Files/Test Images.xcassets/Raizlabs Logo.imageset/Raizlabs Logo@3x.png new file mode 100644 index 0000000..7bbea6b Binary files /dev/null and b/Tests/RZUtilsTests/Supporting Files/Test Images.xcassets/Raizlabs Logo.imageset/Raizlabs Logo@3x.png differ