Giter Site home page Giter Site logo

matthewmincher / maskedlabel Goto Github PK

View Code? Open in Web Editor NEW

This project forked from darincon/maskedlabel

0.0 2.0 0.0 4.83 MB

MaskedLabel is a UILabel subclass that allows you to easily apply a gradient to its text or to make it transparent.

License: MIT License

Swift 92.33% Ruby 4.40% Objective-C 3.26%

maskedlabel's Introduction

MaskedLabel

Language Platform CocoaPods compatible Carthage compatible License

Swift Version MaskedLabel View Version
3.1 0.9.0

MaskedLabel is a UILabel subclass that allows you to easily apply a gradient to its text or to make it transparent.

alt tag

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate MaskedLabel into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'MaskedLabel', '~> 0.9.2'
end

Then, run the following command:

$ pod install

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate MaskedLabel into your Xcode project using Carthage, specify it in your Cartfile:

github "darincon/MaskedLabel" ~> 0.9.2

Run carthage update to build the framework and drag the built MaskedLabel.framework into your Xcode project.

Manually

If you prefer not to use either of the aforementioned dependency managers, you can integrate MaskedLabel into your project manually.

Usage

MaskedLabel can be used both programmatically and with storyboards.

Storyboards

Add a UILabel to your storyboard and change its class to MaskedLabel.

Programatically

  • Initialization without parameters
let maskedLabel = MaskedLabel()
  • Initialization with frame
let maskedLabel = MaskedLabel(frame: CGRect(x: 10, y: 50, width: 200, height: 100))

Setup

There are a few properties you can set to obtain the desired behavior:

  • gradientColors: An array of UIColor that defines the gradient. If it contains only one element, it will be applied as start and end color. In case this property is nil or an empty array, the value of fillColor will be used instead.
  • gradientLocations: The location for each color provided in components. Each location must be a CGFloat value in the range of 0 to 1, inclusive. If 0 and 1 are not in the locations array, Quartz uses the colors provided that are closest to 0 and 1 for those locations.
  • startPoint: The coordinate that defines the starting point of the gradient.
  • endPoint: The coordinate that defines the ending point of the gradient.
  • fillColor: Set this property when a constant color is needed instead of a gradient. If both this property and gradientColors are set, this color is omitted and the gradient will be applied to the text. The default color is black.
  • fillOption: A constant indicating if the gradient, or color, will be applied to the label's background, making the text transparent, or to the text.

Example

let maskedLabel = MaskedLabel()
maskedLabel.gradientColors = [UIColor.red, UIColor.blue]
maskedLabel.startPoint = CGPoint(x: 0.0, y: 0.0)
maskedLabel.endPoint = CGPoint(x: maskedLabel.frame.width, y: maskedLabel.frame.height)
maskedLabel.fillOption = .background
maskedLabel.text = "MaskedLabel"

License

ViewControllerStates is released under the MIT license. See license for details.

maskedlabel's People

Contributors

matthewmincher avatar

Watchers

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