Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added the image noise categories to the main KGNoise file so there is…

… only one thing to add. Also implemented the image category for NSImage and added examples to the sample apps.

fix #2
  • Loading branch information...
commit d43aecf30ad1409990a6c031e209913c3e1858c8 1 parent bae4194
@kgn authored
View
6 Example/KGIOSAppDelegate.m
@@ -21,6 +21,12 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
noiseView.noiseOpacity = 0.3;
[self.window.rootViewController.view addSubview:noiseView];
+ UIImage *image = [[UIImage imageNamed:@"button"] imageWithNoiseOpacity:0.2 andBlendMode:kCGBlendModeDarken];
+ UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
+ imageView.frame = CGRectOffset(imageView.frame, round(CGRectGetMidX(noiseView.bounds)-CGRectGetMidX(imageView.bounds)),
+ round(CGRectGetMidY(noiseView.bounds)-CGRectGetMidY(imageView.bounds)));
+ [noiseView addSubview:imageView];
+
CGRect noiseToolbarViewRect = self.window.rootViewController.view.bounds;
noiseToolbarViewRect.size.height = 48;
noiseToolbarViewRect.origin.y = CGRectGetHeight(self.window.rootViewController.view.bounds)-CGRectGetHeight(noiseToolbarViewRect);
View
1  Example/KGMacAppDelegate.h
@@ -14,5 +14,6 @@
@property (assign) IBOutlet NSWindow *window;
@property (weak) IBOutlet KGNoiseLinearGradientView *viewLeft;
@property (weak) IBOutlet KGNoiseRadialGradientView *viewRight;
+@property (weak) IBOutlet NSImageView *imageView;
@end
View
2  Example/KGMacAppDelegate.m
@@ -19,6 +19,8 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification{
self.viewRight.backgroundColor = [NSColor colorWithCalibratedWhite:0.500 alpha:1.000];
self.viewRight.alternateBackgroundColor = [NSColor colorWithCalibratedWhite:0.750 alpha:1.000];
self.viewRight.noiseOpacity = 0.2;
+
+ self.imageView.image = [[NSImage imageNamed:@"button"] imageWithNoiseOpacity:0.2 andBlendMode:kCGBlendModeDarken];
}
@end
View
14 Example/KGNoiseExample.xcodeproj/project.pbxproj
@@ -19,7 +19,8 @@
73CF1C81160069A1006D9180 /* iOSMain.m in Sources */ = {isa = PBXBuildFile; fileRef = 73CF1C7C160069A1006D9180 /* iOSMain.m */; };
73CF1C82160069A1006D9180 /* KGIOSAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 73CF1C7E160069A1006D9180 /* KGIOSAppDelegate.m */; };
73CF1C8416006B6B006D9180 /* KGNoise.m in Sources */ = {isa = PBXBuildFile; fileRef = 73CF1C46160061B7006D9180 /* KGNoise.m */; };
- 98FA88611602A22A0095CAB5 /* UIImage+KGNoise.m in Sources */ = {isa = PBXBuildFile; fileRef = 98FA88601602A22A0095CAB5 /* UIImage+KGNoise.m */; };
+ 73D468D516CED92B0047905D /* button@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 73D468D416CED92B0047905D /* button@2x.png */; };
+ 73D468D616CED92B0047905D /* button@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 73D468D416CED92B0047905D /* button@2x.png */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -41,8 +42,7 @@
73CF1C7C160069A1006D9180 /* iOSMain.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = iOSMain.m; sourceTree = "<group>"; };
73CF1C7D160069A1006D9180 /* KGIOSAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KGIOSAppDelegate.h; sourceTree = "<group>"; };
73CF1C7E160069A1006D9180 /* KGIOSAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KGIOSAppDelegate.m; sourceTree = "<group>"; };
- 98FA885F1602A22A0095CAB5 /* UIImage+KGNoise.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+KGNoise.h"; sourceTree = "<group>"; };
- 98FA88601602A22A0095CAB5 /* UIImage+KGNoise.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+KGNoise.m"; sourceTree = "<group>"; };
+ 73D468D416CED92B0047905D /* button@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "button@2x.png"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -72,8 +72,7 @@
children = (
73CF1C45160061B7006D9180 /* KGNoise.h */,
73CF1C46160061B7006D9180 /* KGNoise.m */,
- 98FA885F1602A22A0095CAB5 /* UIImage+KGNoise.h */,
- 98FA88601602A22A0095CAB5 /* UIImage+KGNoise.m */,
+ 73D468D416CED92B0047905D /* button@2x.png */,
73CF1C3C160060C5006D9180 /* Mac Example */,
73CF1C7B16006936006D9180 /* iOS Example */,
73CF1C171600604E006D9180 /* Products */,
@@ -204,6 +203,7 @@
buildActionMask = 2147483647;
files = (
73CF1C4316006181006D9180 /* MainMenu.xib in Resources */,
+ 73D468D516CED92B0047905D /* button@2x.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -212,6 +212,7 @@
buildActionMask = 2147483647;
files = (
73B7BF08161FA49400024C46 /* Default-568h@2x.png in Resources */,
+ 73D468D616CED92B0047905D /* button@2x.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -235,7 +236,6 @@
73CF1C81160069A1006D9180 /* iOSMain.m in Sources */,
73CF1C82160069A1006D9180 /* KGIOSAppDelegate.m in Sources */,
73CF1C8416006B6B006D9180 /* KGNoise.m in Sources */,
- 98FA88611602A22A0095CAB5 /* UIImage+KGNoise.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -315,7 +315,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
- "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"\"$(SYSTEM_APPS_DIR)/Xcode.app/Contents/Developer/Library/Frameworks\"",
@@ -334,7 +333,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
- "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"\"$(SYSTEM_APPS_DIR)/Xcode.app/Contents/Developer/Library/Frameworks\"",
View
232 Example/MainMenu.xib
@@ -2,18 +2,20 @@
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="8.00">
<data>
<int key="IBDocument.SystemTarget">1080</int>
- <string key="IBDocument.SystemVersion">12C60</string>
- <string key="IBDocument.InterfaceBuilderVersion">2843</string>
+ <string key="IBDocument.SystemVersion">12C3006</string>
+ <string key="IBDocument.InterfaceBuilderVersion">3084</string>
<string key="IBDocument.AppKitVersion">1187.34</string>
<string key="IBDocument.HIToolboxVersion">625.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string key="NS.object.0">2843</string>
+ <string key="NS.object.0">3084</string>
</object>
<array key="IBDocument.IntegratedClassDependencies">
<string>IBNSLayoutConstraint</string>
<string>NSCustomObject</string>
<string>NSCustomView</string>
+ <string>NSImageCell</string>
+ <string>NSImageView</string>
<string>NSMenu</string>
<string>NSMenuItem</string>
<string>NSSplitView</string>
@@ -1314,7 +1316,6 @@
<int key="NSvFlags">256</int>
<string key="NSFrameSize">{121, 360}</string>
<reference key="NSSuperview" ref="599285279"/>
- <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="712342299"/>
<string key="NSReuseIdentifierKey">_NS:11</string>
<string key="NSClassName">KGNoiseLinearGradientView</string>
@@ -1322,17 +1323,44 @@
<object class="NSCustomView" id="712342299">
<reference key="NSNextResponder" ref="599285279"/>
<int key="NSvFlags">256</int>
+ <array class="NSMutableArray" key="NSSubviews">
+ <object class="NSImageView" id="87572130">
+ <reference key="NSNextResponder" ref="712342299"/>
+ <int key="NSvFlags">268</int>
+ <set class="NSMutableSet" key="NSDragTypes">
+ <string>Apple PDF pasteboard type</string>
+ <string>Apple PICT pasteboard type</string>
+ <string>Apple PNG pasteboard type</string>
+ <string>NSFilenamesPboardType</string>
+ <string>NeXT Encapsulated PostScript v1.2 pasteboard type</string>
+ <string>NeXT TIFF v4.0 pasteboard type</string>
+ </set>
+ <string key="NSFrameSize">{358, 360}</string>
+ <reference key="NSSuperview" ref="712342299"/>
+ <string key="NSReuseIdentifierKey">_NS:9</string>
+ <bool key="NSEnabled">YES</bool>
+ <object class="NSImageCell" key="NSCell" id="914929802">
+ <int key="NSCellFlags">134217728</int>
+ <int key="NSCellFlags2">33554432</int>
+ <string key="NSCellIdentifier">_NS:9</string>
+ <int key="NSAlign">0</int>
+ <int key="NSScale">2</int>
+ <int key="NSStyle">0</int>
+ <bool key="NSAnimates">NO</bool>
+ </object>
+ <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
+ <bool key="NSEditable">YES</bool>
+ </object>
+ </array>
<string key="NSFrame">{{122, 0}, {358, 360}}</string>
<reference key="NSSuperview" ref="599285279"/>
- <reference key="NSWindow"/>
- <reference key="NSNextKeyView"/>
+ <reference key="NSNextKeyView" ref="87572130"/>
<string key="NSReuseIdentifierKey">_NS:13</string>
<string key="NSClassName">KGNoiseRadialGradientView</string>
</object>
</array>
<string key="NSFrameSize">{480, 360}</string>
<reference key="NSSuperview" ref="439893737"/>
- <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="886914388"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="NSIsVertical">YES</bool>
@@ -1341,10 +1369,9 @@
</array>
<string key="NSFrameSize">{480, 360}</string>
<reference key="NSSuperview"/>
- <reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="599285279"/>
</object>
- <string key="NSScreenRect">{{0, 0}, {1440, 900}}</string>
+ <string key="NSScreenRect">{{0, 0}, {1440, 878}}</string>
<string key="NSMaxSize">{10000000000000, 10000000000000}</string>
<bool key="NSWindowIsRestorable">YES</bool>
</object>
@@ -2061,6 +2088,14 @@
</object>
<int key="connectionID">547</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">imageView</string>
+ <reference key="source" ref="976324537"/>
+ <reference key="destination" ref="87572130"/>
+ </object>
+ <int key="connectionID">577</int>
+ </object>
</array>
<object class="IBMutableOrderedSet" key="objectRecords">
<array key="orderedObjects">
@@ -3144,6 +3179,73 @@
<object class="IBObjectRecord">
<int key="objectID">539</int>
<reference key="object" ref="712342299"/>
+ <array class="NSMutableArray" key="children">
+ <object class="IBNSLayoutConstraint" id="817328108">
+ <reference key="firstItem" ref="87572130"/>
+ <int key="firstAttribute">4</int>
+ <int key="relation">0</int>
+ <reference key="secondItem" ref="712342299"/>
+ <int key="secondAttribute">4</int>
+ <float key="multiplier">1</float>
+ <object class="IBLayoutConstant" key="constant">
+ <double key="value">0.0</double>
+ </object>
+ <float key="priority">1000</float>
+ <reference key="containingView" ref="712342299"/>
+ <int key="scoringType">8</int>
+ <float key="scoringTypeFloat">29</float>
+ <int key="contentType">3</int>
+ </object>
+ <object class="IBNSLayoutConstraint" id="496534312">
+ <reference key="firstItem" ref="87572130"/>
+ <int key="firstAttribute">6</int>
+ <int key="relation">0</int>
+ <reference key="secondItem" ref="712342299"/>
+ <int key="secondAttribute">6</int>
+ <float key="multiplier">1</float>
+ <object class="IBLayoutConstant" key="constant">
+ <double key="value">0.0</double>
+ </object>
+ <float key="priority">1000</float>
+ <reference key="containingView" ref="712342299"/>
+ <int key="scoringType">8</int>
+ <float key="scoringTypeFloat">29</float>
+ <int key="contentType">3</int>
+ </object>
+ <object class="IBNSLayoutConstraint" id="1071686508">
+ <reference key="firstItem" ref="87572130"/>
+ <int key="firstAttribute">3</int>
+ <int key="relation">0</int>
+ <reference key="secondItem" ref="712342299"/>
+ <int key="secondAttribute">3</int>
+ <float key="multiplier">1</float>
+ <object class="IBLayoutConstant" key="constant">
+ <double key="value">0.0</double>
+ </object>
+ <float key="priority">1000</float>
+ <reference key="containingView" ref="712342299"/>
+ <int key="scoringType">8</int>
+ <float key="scoringTypeFloat">29</float>
+ <int key="contentType">3</int>
+ </object>
+ <object class="IBNSLayoutConstraint" id="1034794513">
+ <reference key="firstItem" ref="87572130"/>
+ <int key="firstAttribute">5</int>
+ <int key="relation">0</int>
+ <reference key="secondItem" ref="712342299"/>
+ <int key="secondAttribute">5</int>
+ <float key="multiplier">1</float>
+ <object class="IBLayoutConstant" key="constant">
+ <double key="value">0.0</double>
+ </object>
+ <float key="priority">1000</float>
+ <reference key="containingView" ref="712342299"/>
+ <int key="scoringType">8</int>
+ <float key="scoringTypeFloat">29</float>
+ <int key="contentType">3</int>
+ </object>
+ <reference ref="87572130"/>
+ </array>
<reference key="parent" ref="599285279"/>
</object>
<object class="IBObjectRecord">
@@ -3166,6 +3268,39 @@
<reference key="object" ref="868428510"/>
<reference key="parent" ref="439893737"/>
</object>
+ <object class="IBObjectRecord">
+ <int key="objectID">548</int>
+ <reference key="object" ref="87572130"/>
+ <array class="NSMutableArray" key="children">
+ <reference ref="914929802"/>
+ </array>
+ <reference key="parent" ref="712342299"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">549</int>
+ <reference key="object" ref="914929802"/>
+ <reference key="parent" ref="87572130"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">572</int>
+ <reference key="object" ref="1034794513"/>
+ <reference key="parent" ref="712342299"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">574</int>
+ <reference key="object" ref="1071686508"/>
+ <reference key="parent" ref="712342299"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">575</int>
+ <reference key="object" ref="496534312"/>
+ <reference key="parent" ref="712342299"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">576</int>
+ <reference key="object" ref="817328108"/>
+ <reference key="parent" ref="712342299"/>
+ </object>
</array>
</object>
<dictionary class="NSMutableDictionary" key="flattenedProperties">
@@ -3318,13 +3453,26 @@
<boolean value="NO" key="537.IBNSViewMetadataTranslatesAutoresizingMaskIntoConstraints"/>
<string key="537.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="538.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <array key="539.IBNSViewMetadataConstraints">
+ <reference ref="1034794513"/>
+ <reference ref="1071686508"/>
+ <reference ref="496534312"/>
+ <reference ref="817328108"/>
+ </array>
<string key="539.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="541.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="543.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="544.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="545.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <boolean value="NO" key="548.IBNSViewMetadataTranslatesAutoresizingMaskIntoConstraints"/>
+ <string key="548.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string key="549.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="56.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="57.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string key="572.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string key="574.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string key="575.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string key="576.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="58.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="72.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="73.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -3342,71 +3490,9 @@
<nil key="activeLocalization"/>
<dictionary class="NSMutableDictionary" key="localizations"/>
<nil key="sourceID"/>
- <int key="maxID">547</int>
- </object>
- <object class="IBClassDescriber" key="IBDocument.Classes">
- <array class="NSMutableArray" key="referencedPartialClassDescriptions">
- <object class="IBPartialClassDescription">
- <string key="className">KGMacAppDelegate</string>
- <string key="superclassName">NSObject</string>
- <dictionary class="NSMutableDictionary" key="outlets">
- <string key="viewLeft">KGNoiseRadialGradientView</string>
- <string key="viewRight">KGNoiseLinearGradientView</string>
- <string key="window">NSWindow</string>
- </dictionary>
- <dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
- <object class="IBToOneOutletInfo" key="viewLeft">
- <string key="name">viewLeft</string>
- <string key="candidateClassName">KGNoiseRadialGradientView</string>
- </object>
- <object class="IBToOneOutletInfo" key="viewRight">
- <string key="name">viewRight</string>
- <string key="candidateClassName">KGNoiseLinearGradientView</string>
- </object>
- <object class="IBToOneOutletInfo" key="window">
- <string key="name">window</string>
- <string key="candidateClassName">NSWindow</string>
- </object>
- </dictionary>
- <object class="IBClassDescriptionSource" key="sourceIdentifier">
- <string key="majorKey">IBProjectSource</string>
- <string key="minorKey">./Classes/KGMacAppDelegate.h</string>
- </object>
- </object>
- <object class="IBPartialClassDescription">
- <string key="className">KGNoiseLinearGradientView</string>
- <string key="superclassName">KGNoiseView</string>
- <object class="IBClassDescriptionSource" key="sourceIdentifier">
- <string key="majorKey">IBProjectSource</string>
- <string key="minorKey">./Classes/KGNoiseLinearGradientView.h</string>
- </object>
- </object>
- <object class="IBPartialClassDescription">
- <string key="className">KGNoiseRadialGradientView</string>
- <string key="superclassName">KGNoiseView</string>
- <object class="IBClassDescriptionSource" key="sourceIdentifier">
- <string key="majorKey">IBProjectSource</string>
- <string key="minorKey">./Classes/KGNoiseRadialGradientView.h</string>
- </object>
- </object>
- <object class="IBPartialClassDescription">
- <string key="className">KGNoiseView</string>
- <string key="superclassName">UIView</string>
- <object class="IBClassDescriptionSource" key="sourceIdentifier">
- <string key="majorKey">IBProjectSource</string>
- <string key="minorKey">./Classes/KGNoiseView.h</string>
- </object>
- </object>
- <object class="IBPartialClassDescription">
- <string key="className">NSLayoutConstraint</string>
- <string key="superclassName">NSObject</string>
- <object class="IBClassDescriptionSource" key="sourceIdentifier">
- <string key="majorKey">IBProjectSource</string>
- <string key="minorKey">./Classes/NSLayoutConstraint.h</string>
- </object>
- </object>
- </array>
+ <int key="maxID">577</int>
</object>
+ <object class="IBClassDescriber" key="IBDocument.Classes"/>
<int key="IBDocument.localizationMode">0</int>
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaFramework</string>
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
View
16 Example/UIColor+KGNoise.h
@@ -1,16 +0,0 @@
-//
-// UIColor+KGNoise.h
-// KGNoiseExample
-//
-// Created by Cory Imdieke on 9/14/12.
-// Copyright (c) 2012 BitSuites, LLC. All rights reserved.
-//
-
-#import <UIKit/UIKit.h>
-
-@interface UIColor (KGNoise)
-
-- (UIColor *)colorWithNoiseOpacity:(CGFloat)opacity;
-- (UIColor *)colorWithNoiseOpacity:(CGFloat)opacity andBlendMode:(CGBlendMode)blendMode;
-
-@end
View
56 Example/UIColor+KGNoise.m
@@ -1,56 +0,0 @@
-//
-// UIColor+KGNoise.m
-// KGNoiseExample
-//
-// Created by Cory Imdieke on 9/14/12.
-// Copyright (c) 2012 BitSuites, LLC. All rights reserved.
-//
-
-#import "UIColor+KGNoise.h"
-#import "KGNoise.h"
-
-@implementation UIColor (KGNoise)
-
-- (UIColor *)colorWithNoiseOpacity:(CGFloat)opacity{
- return [self colorWithNoiseOpacity:opacity andBlendMode:kCGBlendModeScreen];
-}
-
-- (UIColor *)colorWithNoiseOpacity:(CGFloat)opacity andBlendMode:(CGBlendMode)blendMode{
- // Figure out our screen scale, if it's a retina display we'll make the noise at twice the resolution
- CGFloat screenScale = [[UIScreen mainScreen] scale];
-
- // Create a context to draw in
- CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
- CGContextRef context = CGBitmapContextCreate(NULL,
- 256.0 * screenScale,
- 256.0 * screenScale,
- 8, /* bits per channel */
- (256.0 * screenScale * 4), /* 4 channels per pixel * numPixels/row */
- colorSpace,
- kCGImageAlphaPremultipliedLast);
- CGColorSpaceRelease(colorSpace);
-
- UIGraphicsPushContext(context);
-
- // Fill with the color
- CGContextSetFillColorWithColor(context, [self CGColor]);
- CGContextFillRect(context, CGRectMake(0.0, 0.0, 256.0 * screenScale, 256.0 * screenScale));
-
- // Noise on top
- [KGNoise drawNoiseWithOpacity:opacity andBlendMode:blendMode];
-
- // Create a CGImage from the context
- CGImageRef rawImage = CGBitmapContextCreateImage(context);
- UIGraphicsPopContext();
- CGContextRelease(context);
-
- // Create a UIImage from the CGImage
- UIImage *finishedImage = [UIImage imageWithCGImage:rawImage];
- CGImageRelease(rawImage);
-
- UIColor *patternColor = [UIColor colorWithPatternImage:finishedImage];
-
- return patternColor;
-}
-
-@end
View
16 Example/UIImage+KGNoise.h
@@ -1,16 +0,0 @@
-//
-// UIImage+KGNoise.h
-// KGNoiseExample
-//
-// Created by Cory Imdieke on 9/13/12.
-// Copyright (c) 2012 BitSuites, LLC. All rights reserved.
-//
-
-#import <UIKit/UIKit.h>
-
-@interface UIImage (KGNoise)
-
-- (UIImage *)imageWithNoiseOpacity:(CGFloat)opacity;
-- (UIImage *)imageWithNoiseOpacity:(CGFloat)opacity andBlendMode:(CGBlendMode)blendMode;
-
-@end
View
60 Example/UIImage+KGNoise.m
@@ -1,60 +0,0 @@
-//
-// UIImage+KGNoise.m
-// KGNoiseExample
-//
-// Created by Cory Imdieke on 9/13/12.
-// Copyright (c) 2012 BitSuites, LLC. All rights reserved.
-//
-
-#import "UIImage+KGNoise.h"
-#import "KGNoise.h"
-
-@implementation UIImage (KGNoise)
-
-- (UIImage *)imageWithNoiseOpacity:(CGFloat)opacity{
- return [self imageWithNoiseOpacity:opacity andBlendMode:kCGBlendModeScreen];
-}
-
-- (UIImage *)imageWithNoiseOpacity:(CGFloat)opacity andBlendMode:(CGBlendMode)blendMode{
- // Create a context to draw in
- CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
- CGContextRef context = CGBitmapContextCreate(NULL,
- self.size.width * self.scale,
- self.size.height * self.scale,
- 8, /* bits per channel */
- (self.size.width * self.scale * 4), /* 4 channels per pixel * numPixels/row */
- colorSpace,
- kCGImageAlphaPremultipliedLast);
- CGColorSpaceRelease(colorSpace);
-
- CGContextSaveGState(context);
-
- // Flip context
- CGContextTranslateCTM(context, 0, self.size.height * self.scale);
- CGContextScaleCTM(context, self.scale, -self.scale);
-
- UIGraphicsPushContext(context);
-
- // Draw the image
- [self drawAtPoint:CGPointMake(0.0, 0.0)];
-
- CGContextRestoreGState(context);
-
- CGContextClipToMask(context, CGRectMake(0.0, 0.0, self.size.width * self.scale, self.size.height * self.scale), [self CGImage]);
-
- // Noise on top
- [KGNoise drawNoiseWithOpacity:opacity andBlendMode:blendMode];
-
- // Create a CGImage from the context
- CGImageRef rawImage = CGBitmapContextCreateImage(context);
- UIGraphicsPopContext();
- CGContextRelease(context);
-
- // Create a UIImage from the CGImage
- UIImage *finishedImage = [UIImage imageWithCGImage:rawImage scale:self.scale orientation:self.imageOrientation];
- CGImageRelease(rawImage);
-
- return finishedImage;
-}
-
-@end
View
BIN  Example/button@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
14 KGNoise.h
@@ -36,6 +36,20 @@
@end
#endif
+#pragma mark - KGNoise Image
+
+#if TARGET_OS_IPHONE
+@interface UIImage(KGNoise)
+- (UIImage *)imageWithNoiseOpacity:(CGFloat)opacity;
+- (UIImage *)imageWithNoiseOpacity:(CGFloat)opacity andBlendMode:(CGBlendMode)blendMode;
+@end
+#else
+@interface NSImage(KGNoise)
+- (NSImage *)imageWithNoiseOpacity:(CGFloat)opacity;
+- (NSImage *)imageWithNoiseOpacity:(CGFloat)opacity andBlendMode:(CGBlendMode)blendMode;
+@end
+#endif
+
#pragma mark - KGNoiseView
#if TARGET_OS_IPHONE
View
44 KGNoise.m
@@ -139,6 +139,50 @@ - (NSColor *)colorWithNoiseWithOpacity:(CGFloat)opacity andBlendMode:(CGBlendMod
@end
#endif
+#pragma mark - KGNoise Image
+
+#if TARGET_OS_IPHONE
+@implementation UIImage(KGNoise)
+- (UIImage *)imageWithNoiseOpacity:(CGFloat)opacity{
+ return [self imageWithNoiseOpacity:opacity andBlendMode:kCGBlendModeScreen];
+}
+- (UIImage *)imageWithNoiseOpacity:(CGFloat)opacity andBlendMode:(CGBlendMode)blendMode{
+ CGRect rect = {CGPointZero, self.size};
+ UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0.0f);
+ CGContextRef context = UIGraphicsGetCurrentContext();
+ CGContextSaveGState(context);
+ [self drawAtPoint:CGPointZero];
+ CGContextScaleCTM(context, 1, -1);
+ CGContextTranslateCTM(context, 0, -CGRectGetHeight(rect));
+ CGContextClipToMask(context, rect, [self CGImage]);
+ [KGNoise drawNoiseWithOpacity:opacity andBlendMode:blendMode];
+ CGContextRestoreGState(context);
+ UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
+ UIGraphicsEndImageContext();
+ return image;
+}
+@end
+#else
+@implementation NSImage(KGNoise)
+- (NSImage *)imageWithNoiseOpacity:(CGFloat)opacity{
+ return [self imageWithNoiseOpacity:opacity andBlendMode:kCGBlendModeScreen];
+}
+- (NSImage *)imageWithNoiseOpacity:(CGFloat)opacity andBlendMode:(CGBlendMode)blendMode{
+ CGRect rect = {CGPointZero, self.size};
+ NSImage *image = [[NSImage alloc] initWithSize:rect.size];
+ [image lockFocus];
+ CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];
+ CGContextSaveGState(context);
+ [self drawAtPoint:CGPointZero fromRect:CGRectZero operation:NSCompositeSourceOver fraction:1];
+ CGContextClipToMask(context, rect, [self CGImageForProposedRect:NULL context:[NSGraphicsContext currentContext] hints:nil]);
+ [KGNoise drawNoiseWithOpacity:opacity andBlendMode:blendMode];
+ CGContextRestoreGState(context);
+ [image unlockFocus];
+ return image;
+}
+@end
+#endif
+
#pragma mark - KGNoiseView
@implementation KGNoiseView
Please sign in to comment.
Something went wrong with that request. Please try again.