The RCRTimeLabel is a lightweight time label generator for iOS that displays time in a human-readable format. It simplifies the process of displaying the time elapsed or remaining in a user-friendly manner.
Features
- Supports both elapsed and remaining time display
- Displays time in a human-readable format such as “3 hours ago”
- Automatically updates the displayed time at a specified interval
- Configurable time formatting options
- Supports localization with customizable time strings
- Flexible customization options for fonts, colors, and appearance
Installation
To install RCRTimeLabel into your project, you can use CocoaPods. Add the following line to your Podfile:
pod 'RCRTimeLabel'
Then, run the following command:
pod install
Usage
Import the RCRTimeLabel in your view controller or wherever you want to use it:
import RCRTimeLabel
In your code, initialize an instance of RCRTimeLabel:
let timeLabel = RCRTimeLabel()
After initializing the timeLabel, set its frame, font, and other desired properties:
timeLabel.frame = CGRect(x: 0, y: 0, width: 200, height: 30) timeLabel.font = UIFont.systemFont(ofSize: 15) timeLabel.textColor = UIColor.black
To display elapsed time, set the elapsed
property and specify the start time. Use the updateTimeInterval
property to specify how frequently you want the time to be updated:
timeLabel.elapsed = true timeLabel.startTime = Date() // Replace with your actual start time timeLabel.updateTimeInterval = 1
To display remaining time, set the elapsed
property to false
and specify the end time:
timeLabel.elapsed = false timeLabel.endTime = Date() // Replace with your actual end time
To start updating the time display, call the startUpdating()
method:
timeLabel.startUpdating()
Finally, add the timeLabel to your view hierarchy:
view.addSubview(timeLabel)
Customization
The RCRTimeLabel can be customized to match your app’s design. Here are some options you can customize:
- Font: Use the
font
property to change the time label’s font. - Color: Use the
textColor
property to change the time label’s text color. - Localization: Use the
timeStrings
property to customize the time strings used in different locales. Consult the documentation for more details.
Feel free to explore the documentation and source code for further customization options.
Requirements
The RCRTimeLabel library is compatible with iOS 10 and above.
License
The RCRTimeLabel library is available under the MIT license. See the LICENSE file for more information.