All Projects → tobihagemann → Thlabel

tobihagemann / Thlabel

Licence: other
UILabel subclass, which additionally allows shadow blur, inner shadow, stroke text and fill gradient.

Projects that are alternatives of or similar to Thlabel

Rwidgethelper
Android UI 快速开发,专治原生控件各种不服
Stars: ✭ 996 (+56.6%)
Mutual labels:  gradient, shadow
Xamarin.forms.backgroundkit
🔨 A powerful Kit for customizing the background of Xamarin.Forms views
Stars: ✭ 167 (-73.74%)
Mutual labels:  gradient, shadow
Android-SGTextView
同时带字体描边 渐变 阴影的TextView - both have stroker, gradient and shadow TextView
Stars: ✭ 18 (-97.17%)
Mutual labels:  gradient, shadow
React Native Cardview
Native CardView for react-native (All Android version and iOS)
Stars: ✭ 426 (-33.02%)
Mutual labels:  shadow
Chromatic Sketch
Sketch plugin for creating good-looking and perceptually uniform gradients and color scales.
Stars: ✭ 445 (-30.03%)
Mutual labels:  gradient
Granim.js
Create fluid and interactive gradient animations with this small javascript library.
Stars: ✭ 4,825 (+658.65%)
Mutual labels:  gradient
Gradientloadingbar
⌛️A customizable animated gradient loading bar.
Stars: ✭ 569 (-10.53%)
Mutual labels:  gradient
Activelabel.swift
UILabel drop-in replacement supporting Hashtags (#), Mentions (@) and URLs (http://) written in Swift
Stars: ✭ 3,942 (+519.81%)
Mutual labels:  uilabel
Hero Generator
🦸🏻‍♀️Hero Generator! Create a nice hero image for your site or app
Stars: ✭ 549 (-13.68%)
Mutual labels:  gradient
Cardview
小票形状的CardView,可以修改阴影颜色
Stars: ✭ 494 (-22.33%)
Mutual labels:  shadow
React Native Neomorph Shadows
Shadows and neumorphism/neomorphism for iOS & Android (like iOS).
Stars: ✭ 478 (-24.84%)
Mutual labels:  shadow
Nudein
An easy-to-use attributed text view for iOS Apps,use like masonry
Stars: ✭ 450 (-29.25%)
Mutual labels:  uilabel
Attributedlabel
Easy to use, fast, and higher performance than UILabel.
Stars: ✭ 514 (-19.18%)
Mutual labels:  uilabel
Enzyme
High-performance automatic differentiation of LLVM.
Stars: ✭ 418 (-34.28%)
Mutual labels:  gradient
Shadowlayout
This library allows you to create a shadow effect for your layout based on your child.
Stars: ✭ 553 (-13.05%)
Mutual labels:  shadow
Shadowview
An iOS Library that makes shadows management easy on UIView.
Stars: ✭ 391 (-38.52%)
Mutual labels:  shadow
Unitypcss
Nvidia's PCSS soft shadow algorithm implemented in Unity
Stars: ✭ 533 (-16.19%)
Mutual labels:  shadow
Gradient String
🌈 Beautiful color gradients in terminal output
Stars: ✭ 476 (-25.16%)
Mutual labels:  gradient
Coloredshadowimageview
ColoredShadowImageView allows you to create a beautiful shadow around the image based on corresponding area colors.
Stars: ✭ 454 (-28.62%)
Mutual labels:  shadow
Autoscrolllabel
Provides marquee like UILabel scrolling, think Music.app track title scrolling. For Obj-C & Swift.
Stars: ✭ 499 (-21.54%)
Mutual labels:  uilabel

THLabel

CocoaPods Compatible Carthage Compatible Platform Twitter

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

THLabel screenshot

Requirements

  • iOS 4.0 or higher (below iOS 7.0 is untested though)
  • ARC enabled

Installation

The easiest way to use THLabel in your app is via CocoaPods.

  1. Add the following line in the project's Podfile file: pod 'THLabel', '~> 1.4.0'
  2. Run the command pod install from the Podfile folder directory.

Manual Installation

  1. Add CoreText.framework to your Link Binary with Libraries list.
  2. Drag these files into your project: THLabel.h, THLabel.m

IBDesignable / IBInspectable

There is an ibdesignable branch, if you're interested in this feature. It has been removed from the master branch, because IBDesignable and IBInspectable cause problems with CocoaPods, if you're not using use_frameworks! in your Podfile.

Usage

You can create THLabels programmatically, or create them in Interface Builder by dragging an ordinary UILabel into your view and setting its Custom Class to THLabel. With Xcode 6 you can set most of the properties within Interface Builder, which will preview your changes immediately.

Properties

Spacing

@property CGFloat letterSpacing;
@property CGFloat lineSpacing;

You can modify letter spacing of the text (also known as kerning) by changing the letterSpacing property. The default value is 0.0. A positive value will separate the characters, whereas a negative value will make them closer.

Modify line spacing of the text (also known as leading) by changing the lineSpacing property. The default value is 0.0. Only positive values will have an effect.

Shadow Blur

@property CGFloat shadowBlur;

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

Inner Shadow

@property CGFloat innerShadowBlur;
@property CGSize innerShadowOffset;
@property UIColor *innerShadowColor;

The inner shadow has similar properties as UILabel's shadow, once again additionally with a shadow blur. If an inner shadow and a stroke are overlapping, it will appear beneath the stroke.

Stroke Text

@property CGFloat strokeSize;
@property UIColor *strokeColor;
@property 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.

Fill Gradient

@property UIColor *gradientStartColor;
@property UIColor *gradientEndColor;
@property NSArray *gradientColors;
@property CGPoint gradientStartPoint;
@property CGPoint gradientEndPoint;

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.

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

Fade Truncating

@property THLabelFadeTruncatingMode fadeTruncatingMode;

You can fade in/out your label by setting the fadeTruncatingMode property. Default value is THLabelFadeTruncatingModeNone. The options are THLabelFadeTruncatingModeTail, THLabelFadeTruncatingModeHead and THLabelFadeTruncatingModeHeadAndTail.

Text Insets / Padding

@property UIEdgeInsets textInsets;
@property BOOL automaticallyAdjustTextInsets;

Effects like stroke and shadow can't be drawn outside of the bounds of the label view. You may need to set text insets to move a bit away from the edge so that the effects don't get clipped. This will be automatically done if you set automaticallyAdjustTextInsets to YES, which is also the default value.

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.

However THLabel doesn't respect the numberOfLines property, because Core Text doesn't support it natively. If you would like to have multiple lines, set lineBreakMode to NSLineBreakByWordWrapping.

THLabels are slower to draw than UILabels, so be aware of that.

Credits

Original source and inspiration from:

Big thanks to Jason Miller for showing me sample code of his implementation using Core Text! It inspired me to dig deeper and move away from drawing with NSAttributedString on iOS 7, which caused a lot of problems.

License

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

Contact

Tobias Hagemann

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].