SwiftyHolidayUtil is a library for highlighting holidays. Japanese README is here.
To run the example project, clone the repo, and run pod install
from the Example directory first.
- Swit 4.2
SwiftyHolidayUtil is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'SwiftyHolidayUtil'
Very easy as it can be used as extension of UILabel.
import SwiftyHolidayUtil
let label:UILabel = UILabel()
label.frame = CGRect(x: 0, y: 0, width: 200, height: 20)
label.date = Date()
If the locale of your device is "en_US", it is displayed as follows.
SwiftyHolidayUtil.dateStyle
dateStyle |
---|
.short |
.medium (default) |
.long |
.custom(customFormat:String) |
label.dateStyle = .short
label.date = Date()
label.dateStyle = .long
label.date = Date()
label.locale = Locale(identifier: "ja_JP")
label.dateStyle = .long
label.date = Date()
label.locale = Locale(identifier: "ja_JP")
label.dateStyle = .mediunm
label.date = Date()
SwiftyHolidayUtil.holidayFormatOptions
FormatOptionKey | value |
---|---|
.holidayColor | UIColor or HexString (ex. "#FF0000") |
.saturdayColor | UIColor or HexString |
.sundayColor | UIColor or HexString |
.weekSymbolType | WeekSymbolType.standalone / .short / .veryshort |
.weekPosision | WeekPosition.head / .tail |
.shortWeekPrefix | String : Prefix of week string at long date style |
.shortWeekSuffix | String : Suffix of week String at short date style |
.mediumWeekPrefix | String : Prefix of week String at medium date syle |
.mediumWeekSuffix | String : Suffix of week String at short date Style |
.longWeekPrefix | String : Prefix of week String at long date Style |
.longWeekSuffix | String : Suffix of week String at long date Style |
.timeStyle | TimeStyle.long / .medium / .short / .none(default) / .full / .custom(customFormat: String) |
label.locale = Locale(identifier: "ja_JP")
label.dateStyle = .mediunm
label.holidayFormatOptions = [
.holidayColor: "#077705",
.mediumWeekPrefix: "【",
.mediumWeekSuffix: "】",
.weekPosision: SwiftyHolidayUtil.WeekPosition.head
]
label.date = Date()
In my country Japan, We express blue on Saturday and red on Sundays and holidays. In your country, what color do you express on Saturdays, Sundays and holidays?
Please pull request region code and colors.
- HolidayUtil+defaulRegionOptions.swift
"JP": [
FormatOptionKey.saturdayColor: UIColor.blue,
FormatOptionKey.sundayColor: UIColor.red,
FormatOptionKey.holidayColor: UIColor.red
]
Currently it is implemented only in Japan's holiday calculation logic.
fumiyasac/handMadeCalendarOfSwift
US, Korea, Vietnam have implemented provisional logic. However, it is incomplete which can only calculate the holiday of 2019. If you have perfect logic in your country, please implement and pull request.
kazuomatz, getlasterror@gmail.com
SwiftyHolidayUtil is available under the MIT license. See the LICENSE file for more info.