Code Monkey home page Code Monkey logo

sycompositor's Introduction

SYCompositor

Easy, flexible drawing in Objective-C. Sometimes dynamically generating Core Graphics drawing code can be a real pain. SYCompositor makes it really simple to do in Objective-C. Simply provide NSDictionary's for each layer. SYCompositor handles everything else. Drawing, caching, you name it.

Example

// Build your cache key to be unique per your layer confiruation
NSString *cacheKey = @"some-key";

// Get the image from SYCompositor
UIImage *image = [SYCompositor imageWithKey:cacheKey];

// If the image is `nil`, you should build it
if (image == nil) {
	// Create your layers. See `SYCompositor.h` for a full list of available keys
	NSArray *layers = [[NSArray alloc] initWithObjects:
					   // Lens
					   [NSDictionary dictionaryWithObjectsAndKeys:
						@"lens.png", kSYCompositorImageNameKey,
						[NSValue valueWithCGRect:CGRectMake(88.0f, 275.0f, 138.0f, 138.0f)], kSYCompositorRectKey,
						nil],

					   // Body layer
					   [NSDictionary dictionaryWithObjectsAndKeys:
						@"camera-body.png", kSYCompositorMaskImageNameKey,
						bodyColor, kSYCompositorColorKey,
						nil],

					   // Shadows layer
					   [NSDictionary dictionaryWithObjectsAndKeys:
						@"camera-shadows.png", kSYCompositorImageNameKey,
						@"Multiply", kSYCompositorModeKey,
						nil],
					   nil];

	// Create the image. This will store it in the cache automatically.
	image = [SYCompositor imageWithLayers:layers size:[[UIScreen mainScreen] bounds].size key:cacheKey];
}

// Now `image` is ready to go!
someImageView.image = image;

Adding to Your Project

Be sure to initialize the SYCache submodule:

$ cd whereverYouClonedSYCompositor
$ git submodule update --init

Then add SYCompostor.h, SYCompositor.h, SYCache/SYCache.h, and SYCache/SYCache.m to your project.

ARC

If you are including SYCompositor in a project that uses Automatic Reference Counting (ARC) enabled, you will need to set the -fno-objc-arc compiler flag on all of the SYCompositor and SYCache source files. To do this in Xcode, go to your active target and select the "Build Phases" tab. In the "Compiler Flags" column, set -fno-objc-arc for each of the SYCompositor and SYCache source files.

sycompositor's People

Contributors

soffes avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.