ResponsiveLabel is a customizable UILabel subclass that automatically adjusts its font size to fit the available width. It provides a simple way to create dynamic and visually appealing labels that adapt to different screen sizes and orientations.
Features
- Automatic font size adjustment for label text
- Supports both single-line and multi-line labels
- Customizable label appearance
- Flexible and easy to integrate
- Works in both portrait and landscape orientations
Installation
ResponsiveLabel can be easily installed using CocoaPods, the dependency manager for iOS projects. Simply add the following line to your project’s Podfile:
pod 'ResponsiveLabel'
Then run the command pod install
to install the library and its dependencies to your project.
Usage
To use ResponsiveLabel in your project, follow these steps:
- Add an instance of ResponsiveLabel to your view hierarchy
- Set the desired text for the label using the
text
property - Customize the label appearance as desired
- Optionally, specify the maximum font size using the
maximumFontSize
property - Call
sizeToFit()
to adjust the font size based on the available width
Here’s an example of how to use ResponsiveLabel in your code:
// Create and configure a ResponsiveLabel instance
let responsiveLabel = ResponsiveLabel()
responsiveLabel.text = "Lorem ipsum dolor sit amet"
responsiveLabel.textColor = .black
responsiveLabel.backgroundColor = .white
responsiveLabel.textAlignment = .center
// Specify the maximum font size
responsiveLabel.maximumFontSize = 30
// Adjust the font size based on the available width
responsiveLabel.sizeToFit()
// Add the label to your view hierarchy
view.addSubview(responsiveLabel)
Customization
ResponsiveLabel provides various properties to customize its appearance:
textColor
: The color of the label textfont
: The font used for the label textbackgroundColo
r: The background color of the labeltextAlignment
: The alignment of the label textmaximumFontSize
: The maximum font size for the label text
By customizing these properties, you can achieve the desired appearance for your labels.
Requirements
ResponsiveLabel has the following requirements:
- iOS 9.0 or later
- Swift 4.2 or later
License
ResponsiveLabel is released under the MIT license. See the LICENSE file for more information.
Conclusion
ResponsiveLabel is a powerful UILabel subclass that allows you to create labels that automatically adjust their font size to fit the available width. With its customizable appearance and ease of integration, it’s a great tool for creating dynamic and responsive UI components in your iOS apps.