Skip to content

Instantly share code, notes, and snippets.

@iAmrSalman
Created February 20, 2020 17:57
Show Gist options
  • Save iAmrSalman/23a4da0f1f4fd70c09df04a99f77a6d0 to your computer and use it in GitHub Desktop.
Save iAmrSalman/23a4da0f1f4fd70c09df04a99f77a6d0 to your computer and use it in GitHub Desktop.
func attributedString(for type: DateType, with date: Date) -> NSAttributedString {
let formatter = DateFormatter()
formatter.locale = Locale(identifier: "ar_EG")
formatter.dateFormat = "dd\nMMM\nyyyy"
if type == .hijri {
formatter.calendar = Calendar(identifier: .islamicCivil)
}
var formattedDate = formatter.string(from: date)
formattedDate += "\(type == . hijri ? "هـ" : "م")"
let attributedString = NSMutableAttributedString(string: formattedDate, attributes: [
NSAttributedString.Key.font : UIFont.systemFont(ofSize: 18),
NSAttributedString.Key.foregroundColor : .black
])
return attributedString
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment