Giter Club home page Giter Club logo

thlabel's Introduction

THLabel

THLabel is a subclass of UILabel, which additionally allows shadow blur, stroke text and fill gradient.

THLabel screenshot

Requirements

  • iOS 4.0 or higher
  • ARC enabled

Installation

You only need 2 files:

  • THLabel.h
  • THLabel.m

You can create THLabels programmatically, or create them in Interface Builder by dragging an ordinary UILabel into your view and setting its class to THLabel.

Properties

	@property (nonatomic, assign) CGFloat shadowBlur;

Additionally to UILabel's shadowColor and shadowOffset, you can also set a shadow blur to soften the shadow.

	@property (nonatomic, assign) CGFloat strokeSize;
	@property (nonatomic, strong) UIColor *strokeColor;
	@property (nonatomic, assign) THLabelStrokePosition strokePosition;

You can set an outer, centered or inner stroke by setting the strokePosition property. Default value is THLabelStrokePositionOutside. Other options are THLabelStrokePositionCenter and THLabelStrokePositionInside.

	@property (nonatomic, strong) UIColor *gradientStartColor;
	@property (nonatomic, strong) UIColor *gradientEndColor;
	@property (nonatomic, copy) NSArray *gradientColors;

The gradient can consist of multiple colors, which have to be saved as UIColor objects in the gradientColors array. For more convenience, gradientStartColor and gradientEndColor will fill up the array accordingly.

	@property (nonatomic, assign) CGPoint gradientStartPoint;
	@property (nonatomic, assign) CGPoint gradientEndPoint;

The starting and ending points of the gradient are in the range 0 to 1, where (0, 0) is the top-left and (1, 1) the bottom-right of the text. The default value for gradientStartPoint is (0.5, 0.2) and for gradientEndPoint it is (0.5, 0.8).

	@property (nonatomic, assign) UIEdgeInsets textInsets;

Effects like stroke and shadow can't be drawn outside of the bounds of the label view. For labels that are not center-aligned, you may need to set text insets to move a bit away from the edge.

Notes

THLabel respects (unlike UILabel) the contentMode property, which is used for vertical alignment. The textAlignment still has the higher priority, when it comes to horizontal alignment.

THLabels are slower to draw than UILabels, because it is heavily using Core Graphics, so be aware of that.

Credits

Original source and inspiration from:

License

Distributed under the permissive zlib license. See the LICENSE file for more info.

Contact

Tobias Hagemann

thlabel's People

Contributors

tobihagemann 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.