This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Convert English date to Bangla date. This is only for Bangladesh. WestBengla have different method | |
struct BanglaDate { | |
private let date: Date | |
private let calendar = Calendar(identifier: .gregorian) | |
private let dateComponents: DateComponents | |
private let timeZone = TimeZone(identifier: "Asia/Dhaka")! | |
private let banglaMonths = ["বৈশাখ","জ্যৈষ্ঠ", "আষাঢ়","শ্রাবণ","ভাদ্র", "আশ্বিন","কার্তিক","অগ্রহায়ণ","পৌষ","মাঘ", "ফাল্গুন","চৈত্র"] | |
private let banglaSeasons = ["গ্রীষ্ম", "বর্ষা", "শরৎ", "হেমন্ত", "শীত", "বসন্ত"] | |
private let banglaWeek = ["রবিবার", "সোমবার", "মঙ্গলবার", "বুধবার", "বৃহস্পতিবার", "শুক্রবার", "শনিবার"] | |
private var totalDaysInMonth = [31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 30]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Date format | local | Country or Region | |
---|---|---|---|
yyyy/MM/dd | eu | Basque | |
dd. MM. yyyy. | hr_BA | Croatian (Bosnia & Herzegovina) | |
dd/MM/yyyy | en_CM | English (Cameroon) | |
MM/dd/yyyy | en_BI | English (Burundi) | |
dd/MM/yyyy | en_AE | English (United Arab Emirates) | |
yyyy-MM-dd | rw_RW | Kinyarwanda (Rwanda) | |
dd/MM/yyyy | ast | Asturian | |
dd/MM/yyyy | en_SZ | English (Eswatini) | |
dd.MM.yyyy | he_IL | Hebrew (Israel) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//MARK:- tappedOnLabel | |
@objc func tappedOnLabel(_ gesture: UITapGestureRecognizer) { | |
guard let text = self.lblTermsAndConditions.text else { return } | |
let privacyPolicyRange = (text as NSString).range(of: "privacy policy") | |
let termsAndConditionRange = (text as NSString).range(of: "terms and condition") | |
if gesture.didTapAttributedTextInLabel(label: self.lblTermsAndConditions, inRange: privacyPolicyRange) { | |
print("user tapped on privacy policy text") | |
} else if gesture.didTapAttributedTextInLabel(label: self.lblTermsAndConditions, inRange: termsAndConditionRange){ | |
print("user tapped on terms and conditions text") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
self.lblTermsAndConditions.isUserInteractionEnabled = true | |
let tapgesture = UITapGestureRecognizer(target: self, action: #selector(tappedOnLabel(_ :))) | |
tapgesture.numberOfTapsRequired = 1 | |
self.lblTermsAndConditions.addGestureRecognizer(tapgesture) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UITapGestureRecognizer { | |
func didTapAttributedTextInLabel(label: UILabel, inRange targetRange: NSRange) -> Bool { | |
// Create instances of NSLayoutManager, NSTextContainer and NSTextStorage | |
let layoutManager = NSLayoutManager() | |
let textContainer = NSTextContainer(size: CGSize.zero) | |
let textStorage = NSTextStorage(attributedString: label.attributedText!) | |
// Configure layoutManager and textStorage | |
layoutManager.addTextContainer(textContainer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// let MAX_LENGTH_PHONENUMBER = 15 | |
// let ACCEPTABLE_NUMBERS = "0123456789" | |
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { | |
let newLength: Int = textField.text!.count + string.count - range.length | |
let numberOnly = NSCharacterSet.init(charactersIn: ACCEPTABLE_NUMBERS).inverted | |
let strValid = string.rangeOfCharacter(from: numberOnly) == nil | |
return (strValid && (newLength <= MAX_LENGTH_PHONENUMBER)) |