thlabel

THLabel is a powerful and customizable subclass of UILabel, designed to add visual effects to your iOS app’s text. With THLabel, you can easily enhance your app’s typography by adding features such as gradient colors, shadow effects, stroke effects, and more.

Installation

  1. Open your project in Xcode.
  2. Go to File > Swift Packages > Add Package Dependency.
  3. Enter the following URL in the search bar: https://github.com/tobihagemann/THLabel
  4. Select the latest version of THLabel and click Next.
  5. Choose the target(s) where you want to add THLabel and click Finish.

Usage

To get started with THLabel, follow these steps:

  • Import the THLabel module in the relevant file: import THLabel.
  • Create an instance of THLabel, either programmatically or through Interface Builder.
  • Customize the label’s appearance by using the various properties provided by THLabel, such as gradientStartColor, gradientEndColor, shadowColor, strokeColor, etc.
  • Set the desired text for the label using the text property.
  • Add the label to your view hierarchy using the appropriate method, such as addSubview or NSLayoutConstraint.
  • Enjoy your visually enhanced text!

Example

Here’s a basic example illustrating the usage of THLabel:

“`swift
import UIKit
import THLabel

class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

let thLabel = THLabel(frame: CGRect(x: 20, y: 100, width: 200, height: 50))
thLabel.text = “Hello THLabel”
thLabel.gradientStartColor = UIColor.red
thLabel.gradientEndColor = UIColor.orange
thLabel.strokeColor = UIColor.black
thLabel.strokeSize = 1.5
thLabel.shadowColor = UIColor.gray
thLabel.shadowOffset = CGSize(width: 2, height: 2)

self.view.addSubview(thLabel)
}
}
“`

Features

THLabel offers a variety of features to enhance your app’s text:

  • Gradient Colors: Add a gradient color effect to your text using gradientStartColor and gradientEndColor.
  • Shadow Effects: Apply a shadow effect to your text by setting the shadowColor and shadowOffset properties.
  • Stroke Effects: Add an outline or stroke effect to your text with properties like strokeColor and strokeSize.
  • Inner Shadow: Create an inner shadow effect using innerShadowColor, innerShadowOffset, and innerShadowRadius.
  • Text Glow: Apply a glowing effect to your text using textGlowColor, textGlowSize, and textGlowOffset.
  • Additional Customization: Adjust the properties related to font, alignment, underline, strikeout, letter spacing, and more.

Requirements

To use THLabel, you need the following:

  • iOS 11.0 or later
  • Xcode 12.0 or later
  • Swift 5.4 or later

License

THLabel is released under the MIT License. See the LICENSE file for more details.

Conclusion

THLabel is a versatile and convenient solution to add visually appealing text effects to your iOS app. With its easy-to-use interface and extensive customization options, you can enhance your app’s typography with just a few lines of code. Explore the different features and unleash your creativity with THLabel!