GithubHelp home page GithubHelp logo

colormaskingbutton's Introduction

Color Masking Button

Version License Platform

Create a Masking Button

Color Masking Button uses a CGPath as its mask. You can create a CGPath from a SVG file with PocketSVG. Color Masking Button adjusts its frame to the size of the mask's path. To create different sized buttons, initiate with different sized paths.

// Create path
let myPath = PocketSVG.pathFromSVGFileNamed("mySVGFile").takeUnretainedValue()

// Set the origin of the frame, and Color Masking Button will adjust its frame
let myColorMaskingButton = ColorMaskingButton(origin: myOrigin, withPath: myPath, withDirection: .LeftToRight, withForegroundColor: color1, withBackgroundColor: color2)

Documentation

enum MaskingDirection {
    case LeftToRight
    case RightToLeft
    case TopToBottom
    case BottomToTop
}

Defines the possible directions of the masking effect.

Variables

var direction: MaskingDirection

Returns direction of the color mask. (read-only)

var path: CGPath

Returns the path of the color mask. (read-only)

Methods

init(origin: CGPoint, withPath path: CGPath, withDirection direction: MaskingDirection, withForegroundColor foregroundColor: UIColor, withBackgroundColor backgroundColor: UIColor)

Basic instantiation with a CGPath of the mask. Foreground color denotes the initial color inside the mask. Note that Color Masking Button will readjust its frame size to fit the given CGPath.

func addTarget(target: AnyObject?, action: Selector, forControlEvents controlEvents: UIControlEvents)

Add target to a selector. Color Masking Button is a subclass of UIButton.

func updateColorOffset(targetFrame: CGRect)

Updates the mask's offset according to the target view's frame. Note that both the Color Masking Button and the target view must be in the same superview.

func change(foregroundColor: UIColor?, andBackgroundColor backgroundColor: UIColor?)

Change the color of either the foreground or the background.

func resetColorMask()

Force a reset the color mask.

func setMaskWithPath(path: CGPath)

Change the color mask while preseving color and offset.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • Swift 2.0+
  • iOS 8.0+

Installation

ColorMaskingButton is available through CocoaPods. To install it, simply add the following line to your Podfile:

use_frameworks!
pod "ColorMaskingButton"

Author

Lawrence Tran

License

See the LICENSE file for more info.

colormaskingbutton's People

Contributors

lawrnce avatar

Stargazers

Snehal avatar

Watchers

James Cloos avatar  avatar Snehal 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.