Skip to content

christianroman/CRGradientLabel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CRGradientLabel

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

chroman16@gmail.com

@chroman

About

Custom UILabel subclass with gradient coloured background, written in Swift.

Resources

License

Stars

Watchers

Forks

Packages

No packages published