Latest 0.7
Homepage https://github.com/NSSimpleApps/SWGradientNode
License MIT
Platforms ios 8.0, osx 10.10, requires ARC
Frameworks SpriteKit
Authors

0.2 is for Swift 2.3.

>= 0.3 is for Swift 3.

>= 0.6 is for Swift 4.2.

>= 0.7 is for Swift 5.0.

SWGradientNode is a subclass of SKSpriteNode that draws a sweep gradient around a center point with initial angle.

Place into Podfile
pod 'SWGradientNode/ObjC' (ObjC-project) or
pod 'SWGradientNode/Swift' (Swift-project).

Import #import <SWGradientNode/SWGradientNode.h>
or import SWGradientNode.

This class is suitable for iOS and OSX.

Usage:

@implementation SmoothGradientScene

- (void)didMoveToView:(SKView *)view {
    [super didMoveToView:view];

    self.backgroundColor = [SKColor someColor];

    NSArray<SKColor *> *colors = ...; // some array of colors 

    SWGradientNode *node =
    [[SWGradientNode alloc] initWithColors:colors
                                 locations:nil // or other locations
                                    bounds:view.bounds
                              gradientType:SWGradientTypeSmooth];
    node.innerRadius = someValue;

    [self addChild:node];
}
@end

@implementation ViewController

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    SKView *skView = (SKView *)self.view;

    if (!skView.scene) {

    SmoothGradientScene *smoothGradientScene = [SmoothGradientScene sceneWithSize:skView.bounds.size];
    smoothGradientScene.scaleMode = SKSceneScaleModeAspectFill;

    [skView presentScene:smoothGradientScene];
    }
}

Length of locations array must be less by one than length of colors array.

Choose any of these types: SWGradientTypeSmooth, SWGradientTypeStep.

The center of sweeping gradient between (0.0, 0.0) and (1.0, 1.0).
(0.0, 0.0) is a bottom left corner (OSX) or top left corner (iOS).
(1.0, 1.0) is a top right (OSX) or bottom left corner (iOS).
Default is (0.5, 0.5).

The first color of the gradient starts at initial angle in radians between 0 and 2*PI
0 is to the right along the x axis.
All colors are located in counter-clockwise order.
Default is 0.

The inner radius of the gradient
Node will not draw any gradient inside circle with this radius
Value between 0 and 0.5
Default is 0

Alt text

Latest podspec

{
    "name": "SWGradientNode",
    "version": "0.7",
    "summary": "This is a sweep color gradient.",
    "description": "SWGradientNode is a subclass of SKSpriteNode that draws a sweep gradient around a center point with initial angle. See the README",
    "homepage": "https://github.com/NSSimpleApps/SWGradientNode",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "NSSimpleApps, Sergey Poluyanov": "[email protected]"
    },
    "source": {
        "git": "https://github.com/NSSimpleApps/SWGradientNode.git",
        "tag": "0.7"
    },
    "requires_arc": true,
    "frameworks": "SpriteKit",
    "platforms": {
        "ios": "8.0",
        "osx": "10.10"
    },
    "swift_version": "5.0",
    "default_subspecs": "ObjC",
    "subspecs": [
        {
            "name": "ObjC",
            "source_files": "Source/ObjC/*.{h,m}",
            "public_header_files": "Source/ObjC/SWGradientNode.h"
        },
        {
            "name": "Swift",
            "source_files": "Source/Swift/*.swift"
        }
    ]
}

Pin It on Pinterest

Share This