Latest 1.0.2
Homepage https://github.com/chroman/CRGradientLabel
License MIT
Platforms ios 7.0, requires ARC
Frameworks Foundation
Authors

Custom UILabel subclass with gradient coloured background.

Installation

There are two options:

CocoaPods

  • Add the dependency to your Podfile:

    platform :ios
    pod 'CRGradientLabel'
    ...
  • Run pod install to install the dependencies.

Source files

Just clone this repository or download it in zip-file. Then you will find source files under CRGradientLabel directory. Copy them to your project.

Usage

To use CRGradientLabel, create a CRGradientLabel and add your content.

An example of making a CRGradientLabel:

Swift:

var gradientLabel: CRGradientLabel = CRGradientLabel(frame: CGRectMake(20, 50, 130, 40))
gradientLabel.gradientColors = [UIColor(red: 239 / 255.0, green: 77 / 255.0, blue:182 / 255.0, alpha: 1.0),
UIColor(red: 198 / 255.0, green: 67 / 255.0, blue: 252 / 255.0, alpha: 1.0)]
gradientLabel.textAlignment = NSTextAlignment.Center
gradientLabel.textColor = UIColor.whiteColor()
gradientLabel.text = NSLocalizedString("CRGradientLabel", comment: "")
gradientLabel.font = UIFont.boldSystemFontOfSize(20.0)
self.view.addSubview(gradientLabel)

Objective-C:

CRGradientLabel *gradientLabel = [[CRGradientLabel alloc] initWithFrame:CGRectMake(20, 50, 130, 40)];
gradientLabel.gradientColors = @[[UIColor colorWithRed:239/255.0f green:77/255.0f blue:182/255.0f alpha:1.0f], [UIColor colorWithRed:198/255.0f green:67/255.0f blue:252/255.0f alpha:1.0f]];
gradientLabel.textAlignment = NSTextAlignmentCenter;
gradientLabel.textColor = [UIColor whiteColor];
gradientLabel.text = NSLocalizedString(@"CRGradientLabel", nil);
gradientLabel.font = [UIFont boldSystemFontOfSize:20.0f];
[self.view addSubview:gradientLabel];

Don’t forget to set the gradient colors via an array using the gradientColors property:

Swift:

gradientLabel.gradientColors = [UIColor(red: 239 / 255.0, green: 77 / 255.0, blue:182 / 255.0, alpha: 1.0),
UIColor(red: 198 / 255.0, green: 67 / 255.0, blue: 252 / 255.0, alpha: 1.0)]

Objective-C:

gradientLabel.gradientColors = @[[UIColor colorWithRed:255/255.0f green:42/255.0f blue:104/255.0f alpha:1.0f],
[UIColor colorWithRed:255/255.0f green:90/255.0f blue:58/255.0f alpha:1.0f]];

Requirements

  • iOS 7.0 or higher for Swift.
  • iOS 6.0 or higher for Objective-C.
  • Demo app requires Xcode 6 and iOS 8.0.

License

CRGradientLabel is released under the MIT license. See
LICENSE.

Contact

Christian Roman

http://chroman.me

[email protected]

@chroman

Latest podspec

{
    "name": "CRGradientLabel",
    "version": "1.0.2",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "homepage": "https://github.com/chroman/CRGradientLabel",
    "authors": {
        "Christian Roman": "[email protected]"
    },
    "summary": "Custom UILabel subclass with gradient coloured backgrounds.",
    "source": {
        "git": "https://github.com/chroman/CRGradientLabel.git",
        "tag": "1.0.2"
    },
    "source_files": "CRGradientLabel/Swift/*.swift",
    "frameworks": "Foundation",
    "requires_arc": true,
    "social_media_url": "https://twitter.com/chroman",
    "platforms": {
        "ios": "7.0"
    }
}

Pin It on Pinterest

Share This