Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding KGNoiseLinearGradientView and KGNoiseRadialGradientView closes #5

  • Loading branch information...
commit 6f89947871ee581d86cf293a604f56ad36bb1950 1 parent c6c53a0
@kgn authored
View
27 Example/KGIOSAppDelegate.m
@@ -15,12 +15,31 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [[UIViewController alloc] init];
- KGNoiseView *noiseView = [[KGNoiseView alloc] initWithFrame:self.window.rootViewController.view.bounds];
- noiseView.backgroundColor = [UIColor darkGrayColor];
- noiseView.noiseBlendMode = kCGBlendModeMultiply;
- noiseView.noiseOpacity = 0.1;
+ KGNoiseRadialGradientView *noiseView = [[KGNoiseRadialGradientView alloc] initWithFrame:self.window.rootViewController.view.bounds];
+ noiseView.backgroundColor = [UIColor colorWithRed:0.814 green:0.798 blue:0.747 alpha:1.000];
+ noiseView.alternateBackgroundColor = [UIColor colorWithRed:1.000 green:0.986 blue:0.945 alpha:1.000];
+ noiseView.noiseOpacity = 0.3;
[self.window.rootViewController.view addSubview:noiseView];
+ CGRect noiseToolbarViewRect = self.window.rootViewController.view.bounds;
+ noiseToolbarViewRect.size.height = 48;
+ noiseToolbarViewRect.origin.y = CGRectGetHeight(self.window.rootViewController.view.bounds)-CGRectGetHeight(noiseToolbarViewRect);
+ KGNoiseLinearGradientView *noiseToolbarView = [[KGNoiseLinearGradientView alloc] initWithFrame:noiseToolbarViewRect];
+ noiseToolbarView.backgroundColor = [UIColor colorWithWhite:0.102 alpha:1.000];
+ noiseToolbarView.alternateBackgroundColor = [UIColor colorWithWhite:0.250 alpha:1.000];
+ noiseToolbarView.noiseBlendMode = kCGBlendModeMultiply;
+ noiseToolbarView.noiseOpacity = 0.2;
+ [self.window.rootViewController.view addSubview:noiseToolbarView];
+
+ CGRect noiseNavbarViewRect = self.window.rootViewController.view.bounds;
+ noiseNavbarViewRect.size.height = 48;
+ KGNoiseLinearGradientView *noiseNavbarView = [[KGNoiseLinearGradientView alloc] initWithFrame:noiseNavbarViewRect];
+ noiseNavbarView.backgroundColor = [UIColor colorWithRed:0.307 green:0.455 blue:0.909 alpha:1.000];
+ noiseNavbarView.alternateBackgroundColor = [UIColor colorWithRed:0.363 green:0.700 blue:0.909 alpha:1.000];
+ noiseNavbarView.noiseBlendMode = kCGBlendModeMultiply;
+ noiseNavbarView.noiseOpacity = 0.08;
+ [self.window.rootViewController.view addSubview:noiseNavbarView];
+
[self.window makeKeyAndVisible];
return YES;
}
View
4 Example/KGMacAppDelegate.h
@@ -12,7 +12,7 @@
@interface KGMacAppDelegate : NSObject <NSApplicationDelegate>
@property (assign) IBOutlet NSWindow *window;
-@property (weak) IBOutlet KGNoiseView *viewLeft;
-@property (weak) IBOutlet KGNoiseView *viewRight;
+@property (weak) IBOutlet KGNoiseLinearGradientView *viewLeft;
+@property (weak) IBOutlet KGNoiseRadialGradientView *viewRight;
@end
View
6 Example/KGMacAppDelegate.m
@@ -11,11 +11,13 @@
@implementation KGMacAppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification{
- self.viewLeft.backgroundColor = [NSColor darkGrayColor];
+ self.viewLeft.backgroundColor = [NSColor colorWithCalibratedRed:0.363 green:0.700 blue:0.909 alpha:1.000];
+ self.viewLeft.alternateBackgroundColor = [NSColor colorWithCalibratedRed:0.307 green:0.455 blue:0.909 alpha:1.000];
self.viewLeft.noiseBlendMode = kCGBlendModeMultiply;
self.viewLeft.noiseOpacity = 0.1;
- self.viewRight.backgroundColor = [NSColor lightGrayColor];
+ 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;
}
View
24 Example/KGNoiseExample.xcodeproj/project.pbxproj
@@ -7,9 +7,9 @@
objects = {
/* Begin PBXBuildFile section */
- 7324C77A16006DD4000A0863 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7324C77916006DD4000A0863 /* UIKit.framework */; };
- 7324C77C16006DDF000A0863 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7324C77B16006DDF000A0863 /* Foundation.framework */; };
- 7324C77E16006DFC000A0863 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7324C77D16006DFC000A0863 /* CoreGraphics.framework */; };
+ 73279ECB1631D03A004B8A68 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 73279ECA1631D03A004B8A68 /* CoreGraphics.framework */; };
+ 73279ECD1631D044004B8A68 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 73279ECC1631D044004B8A68 /* UIKit.framework */; };
+ 73279ECF1631D051004B8A68 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 73279ECE1631D051004B8A68 /* Foundation.framework */; };
73B7BF08161FA49400024C46 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 73B7BF07161FA49400024C46 /* Default-568h@2x.png */; };
73CF1C1B1600604E006D9180 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 73CF1C1A1600604E006D9180 /* Cocoa.framework */; };
73CF1C4016006116006D9180 /* KGMacAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 73CF1C3E16006116006D9180 /* KGMacAppDelegate.m */; };
@@ -22,9 +22,9 @@
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
- 7324C77916006DD4000A0863 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/System/Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; };
- 7324C77B16006DDF000A0863 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; };
- 7324C77D16006DFC000A0863 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/System/Library/Frameworks/CoreGraphics.framework; sourceTree = DEVELOPER_DIR; };
+ 73279ECA1631D03A004B8A68 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/System/Library/Frameworks/CoreGraphics.framework; sourceTree = DEVELOPER_DIR; };
+ 73279ECC1631D044004B8A68 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/System/Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; };
+ 73279ECE1631D051004B8A68 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; };
73B7BF07161FA49400024C46 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = "<group>"; };
73CF1C161600604E006D9180 /* KGMacNoiseExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = KGMacNoiseExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
73CF1C1A1600604E006D9180 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
@@ -55,9 +55,9 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
- 7324C77E16006DFC000A0863 /* CoreGraphics.framework in Frameworks */,
- 7324C77C16006DDF000A0863 /* Foundation.framework in Frameworks */,
- 7324C77A16006DD4000A0863 /* UIKit.framework in Frameworks */,
+ 73279ECF1631D051004B8A68 /* Foundation.framework in Frameworks */,
+ 73279ECD1631D044004B8A68 /* UIKit.framework in Frameworks */,
+ 73279ECB1631D03A004B8A68 /* CoreGraphics.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -110,9 +110,9 @@
73CF1C5C160068AD006D9180 /* Frameworks */ = {
isa = PBXGroup;
children = (
- 7324C77D16006DFC000A0863 /* CoreGraphics.framework */,
- 7324C77B16006DDF000A0863 /* Foundation.framework */,
- 7324C77916006DD4000A0863 /* UIKit.framework */,
+ 73279ECE1631D051004B8A68 /* Foundation.framework */,
+ 73279ECC1631D044004B8A68 /* UIKit.framework */,
+ 73279ECA1631D03A004B8A68 /* CoreGraphics.framework */,
);
name = Frameworks;
sourceTree = "<group>";
View
102 Example/MainMenu.xib
@@ -2,13 +2,13 @@
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="8.00">
<data>
<int key="IBDocument.SystemTarget">1080</int>
- <string key="IBDocument.SystemVersion">12B19</string>
- <string key="IBDocument.InterfaceBuilderVersion">2549</string>
- <string key="IBDocument.AppKitVersion">1187</string>
- <string key="IBDocument.HIToolboxVersion">624.00</string>
+ <string key="IBDocument.SystemVersion">12C60</string>
+ <string key="IBDocument.InterfaceBuilderVersion">2843</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">2549</string>
+ <string key="NS.object.0">2843</string>
</object>
<array key="IBDocument.IntegratedClassDependencies">
<string>IBNSLayoutConstraint</string>
@@ -1302,7 +1302,7 @@
<nil key="NSViewClass"/>
<nil key="NSUserInterfaceItemIdentifier"/>
<object class="NSView" key="NSWindowView" id="439893737">
- <nil key="NSNextResponder"/>
+ <reference key="NSNextResponder"/>
<int key="NSvFlags">256</int>
<array class="NSMutableArray" key="NSSubviews">
<object class="NSSplitView" id="599285279">
@@ -1314,21 +1314,25 @@
<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">KGNoiseView</string>
+ <string key="NSClassName">KGNoiseLinearGradientView</string>
</object>
<object class="NSCustomView" id="712342299">
<reference key="NSNextResponder" ref="599285279"/>
<int key="NSvFlags">256</int>
<string key="NSFrame">{{122, 0}, {358, 360}}</string>
<reference key="NSSuperview" ref="599285279"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:13</string>
- <string key="NSClassName">KGNoiseView</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>
@@ -1336,6 +1340,8 @@
</object>
</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>
@@ -3341,52 +3347,54 @@
<object class="IBClassDescriber" key="IBDocument.Classes">
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
<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">NSDocument</string>
- <dictionary class="NSMutableDictionary" key="actions">
- <string key="printDocument:">id</string>
- <string key="revertDocumentToSaved:">id</string>
- <string key="runPageLayout:">id</string>
- <string key="saveDocument:">id</string>
- <string key="saveDocumentAs:">id</string>
- <string key="saveDocumentTo:">id</string>
+ <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="actionInfosByName">
- <object class="IBActionInfo" key="printDocument:">
- <string key="name">printDocument:</string>
- <string key="candidateClassName">id</string>
- </object>
- <object class="IBActionInfo" key="revertDocumentToSaved:">
- <string key="name">revertDocumentToSaved:</string>
- <string key="candidateClassName">id</string>
- </object>
- <object class="IBActionInfo" key="runPageLayout:">
- <string key="name">runPageLayout:</string>
- <string key="candidateClassName">id</string>
- </object>
- <object class="IBActionInfo" key="saveDocument:">
- <string key="name">saveDocument:</string>
- <string key="candidateClassName">id</string>
+ <dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
+ <object class="IBToOneOutletInfo" key="viewLeft">
+ <string key="name">viewLeft</string>
+ <string key="candidateClassName">KGNoiseRadialGradientView</string>
</object>
- <object class="IBActionInfo" key="saveDocumentAs:">
- <string key="name">saveDocumentAs:</string>
- <string key="candidateClassName">id</string>
+ <object class="IBToOneOutletInfo" key="viewRight">
+ <string key="name">viewRight</string>
+ <string key="candidateClassName">KGNoiseLinearGradientView</string>
</object>
- <object class="IBActionInfo" key="saveDocumentTo:">
- <string key="name">saveDocumentTo:</string>
- <string key="candidateClassName">id</string>
+ <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/NSDocument.h</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">
View
24 KGNoise.h
@@ -13,6 +13,8 @@
#import <Cocoa/Cocoa.h>
#endif
+#pragma mark - KGNoise
+
@interface KGNoise : NSObject
+ (void)drawNoiseWithOpacity:(CGFloat)opacity;
@@ -20,6 +22,8 @@
@end
+#pragma mark - KGNoiseView
+
#if TARGET_OS_IPHONE
@interface KGNoiseView : UIView
#else
@@ -29,3 +33,23 @@
@property (nonatomic) CGFloat noiseOpacity;
@property (nonatomic) CGBlendMode noiseBlendMode;
@end
+
+#pragma mark - KGNoiseLinearGradientView
+
+@interface KGNoiseLinearGradientView : KGNoiseView
+#if TARGET_OS_IPHONE
+@property (strong, nonatomic) UIColor *alternateBackgroundColor;
+#else
+@property (strong, nonatomic) NSColor *alternateBackgroundColor;
+#endif
+@end
+
+#pragma mark - KGNoiseRadialGradientView
+
+@interface KGNoiseRadialGradientView : KGNoiseView
+#if TARGET_OS_IPHONE
+@property (strong, nonatomic) UIColor *alternateBackgroundColor;
+#else
+@property (strong, nonatomic) NSColor *alternateBackgroundColor;
+#endif
+@end
View
141 KGNoise.m
@@ -8,6 +8,42 @@
#import "KGNoise.h"
+#if TARGET_OS_IPHONE
+CGFloat *gradientComponentsForColors(UIColor *color1, UIColor *color2){
+#else
+CGFloat *gradientComponentsForColors(NSColor *color1, NSColor *color2){
+#endif
+ CGFloat *components = malloc(8*sizeof(CGFloat));
+ const CGFloat *alternateBackgroundComponents = CGColorGetComponents([color1 CGColor]);
+ if(CGColorGetNumberOfComponents([color1 CGColor]) == 2){
+ components[0] = alternateBackgroundComponents[0];
+ components[1] = alternateBackgroundComponents[0];
+ components[2] = alternateBackgroundComponents[0];
+ components[3] = alternateBackgroundComponents[1];
+ }else{
+ components[0] = alternateBackgroundComponents[0];
+ components[1] = alternateBackgroundComponents[1];
+ components[2] = alternateBackgroundComponents[2];
+ components[3] = alternateBackgroundComponents[3];
+ }
+
+ const CGFloat *backgroundComponents = CGColorGetComponents([color2 CGColor]);
+ if(CGColorGetNumberOfComponents([color2 CGColor]) == 2){
+ components[4] = backgroundComponents[0];
+ components[5] = backgroundComponents[0];
+ components[6] = backgroundComponents[0];
+ components[7] = backgroundComponents[1];
+ }else{
+ components[4] = backgroundComponents[0];
+ components[5] = backgroundComponents[1];
+ components[6] = backgroundComponents[2];
+ components[7] = backgroundComponents[3];
+ }
+ return components;
+}
+
+#pragma mark - KGNoise
+
@implementation KGNoise
+ (void)drawNoiseWithOpacity:(CGFloat)opacity{
@@ -60,6 +96,8 @@ + (void)drawNoiseWithOpacity:(CGFloat)opacity andBlendMode:(CGBlendMode)blendMod
@end
+#pragma mark - KGNoiseView
+
@implementation KGNoiseView
#if TARGET_OS_IPHONE
@@ -135,3 +173,106 @@ - (void)drawRect:(NSRect)dirtyRect{
}
@end
+
+#pragma mark - KGNoiseLinearGradientView
+
+@implementation KGNoiseLinearGradientView
+
+#if TARGET_OS_IPHONE
+- (void)setAlternateBackgroundColor:(UIColor *)alternateBackgroundColor{
+ if(_alternateBackgroundColor != alternateBackgroundColor){
+ _alternateBackgroundColor = alternateBackgroundColor;
+ [self setNeedsDisplay];
+ }
+}
+#else
+- (void)setAlternateBackgroundColor:(NSColor *)alternateBackgroundColor{
+ if(_alternateBackgroundColor != alternateBackgroundColor){
+ _alternateBackgroundColor = alternateBackgroundColor;
+ [self setNeedsDisplay:YES];
+ }
+}
+#endif
+
+#if TARGET_OS_IPHONE
+- (void)drawRect:(CGRect)dirtyRect{
+ CGContextRef context = UIGraphicsGetCurrentContext();
+#else
+- (void)drawRect:(NSRect)dirtyRect{
+ CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];
+#endif
+ // if we don't have an alternate color draw solid
+ if(self.alternateBackgroundColor == nil){
+ [super drawRect:dirtyRect];
+ return;
+ }
+
+ CGRect bounds = self.bounds;
+ CGContextSaveGState(context);
+ CGColorSpaceRef baseSpace = CGColorSpaceCreateDeviceRGB();
+ CGFloat *components = gradientComponentsForColors(self.alternateBackgroundColor, self.backgroundColor);
+ CGGradientRef gradient = CGGradientCreateWithColorComponents(baseSpace, components, NULL, 2);
+ CGColorSpaceRelease(baseSpace), baseSpace = NULL;
+ CGPoint startPoint = CGPointMake(CGRectGetMidX(bounds), CGRectGetMinY(bounds));
+ CGPoint endPoint = CGPointMake(CGRectGetMidX(bounds), CGRectGetMaxY(bounds));
+ CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);
+ CGGradientRelease(gradient), gradient = NULL;
+ CGContextRestoreGState(context);
+ free(components);
+
+ [KGNoise drawNoiseWithOpacity:self.noiseOpacity andBlendMode:self.noiseBlendMode];
+}
+
+@end
+
+#pragma mark - KGNoiseRadialGradientView
+
+@implementation KGNoiseRadialGradientView
+
+#if TARGET_OS_IPHONE
+- (void)setAlternateBackgroundColor:(UIColor *)alternateBackgroundColor{
+ if(_alternateBackgroundColor != alternateBackgroundColor){
+ _alternateBackgroundColor = alternateBackgroundColor;
+ [self setNeedsDisplay];
+ }
+}
+#else
+- (void)setAlternateBackgroundColor:(NSColor *)alternateBackgroundColor{
+ if(_alternateBackgroundColor != alternateBackgroundColor){
+ _alternateBackgroundColor = alternateBackgroundColor;
+ [self setNeedsDisplay:YES];
+ }
+}
+#endif
+
+#if TARGET_OS_IPHONE
+- (void)drawRect:(CGRect)dirtyRect{
+ CGContextRef context = UIGraphicsGetCurrentContext();
+#else
+- (void)drawRect:(NSRect)dirtyRect{
+ CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort];
+#endif
+ // if we don't have an alternate color draw solid
+ if(self.alternateBackgroundColor == nil){
+ [super drawRect:dirtyRect];
+ return;
+ }
+
+ CGRect bounds = self.bounds;
+ CGContextSaveGState(context);
+ size_t gradLocationsNum = 2;
+ CGFloat gradLocations[2] = {0.0f, 1.0f};
+ CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
+ CGFloat *components = gradientComponentsForColors(self.alternateBackgroundColor, self.backgroundColor);
+ CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, components, gradLocations, gradLocationsNum);
+ CGColorSpaceRelease(colorSpace), colorSpace = NULL;
+ CGPoint gradCenter= CGPointMake(round(CGRectGetMidX(bounds)), round(CGRectGetMidY(bounds)));
+ CGFloat gradRadius = MIN(CGRectGetWidth(bounds), CGRectGetHeight(bounds));
+ CGContextDrawRadialGradient(context, gradient, gradCenter, 0, gradCenter, gradRadius, kCGGradientDrawsAfterEndLocation);
+ CGGradientRelease(gradient), gradient = NULL;
+ CGContextRestoreGState(context);
+ free(components);
+
+ [KGNoise drawNoiseWithOpacity:self.noiseOpacity andBlendMode:self.noiseBlendMode];
+}
+@end
Please sign in to comment.
Something went wrong with that request. Please try again.