Skip to content

Instantly share code, notes, and snippets.

View geek-Shayan's full-sized avatar
😎
Let's get the party started !!!

geek-Shayan

😎
Let's get the party started !!!
View GitHub Profile
@SNNafi
SNNafi / English Date to Bangla Date (Swift)
Last active March 30, 2023 08:24
Convert English Date to Bangla Date i.e. 22/03/2021 -> ৮ চৈত্র, ১৪২৭ in Swift. This is only for Bangladesh.
/// 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];
@rvi
rvi / DateFormattersForAllLocales.csv
Last active September 7, 2023 09:52
Date formatter for all locales
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)
@leoiphonedev
leoiphonedev / ViewControllerDetectTextUILabel-2.swift
Created August 7, 2019 05:52
Selector for UITapGestre added to UILable and telling us wether user tap on desired text or not
//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")
}
@leoiphonedev
leoiphonedev / ViewControllerDetectTextUILabel.swift
Created August 7, 2019 05:46
Adding UITapGestureRecognizer to UILabel
self.lblTermsAndConditions.isUserInteractionEnabled = true
let tapgesture = UITapGestureRecognizer(target: self, action: #selector(tappedOnLabel(_ :)))
tapgesture.numberOfTapsRequired = 1
self.lblTermsAndConditions.addGestureRecognizer(tapgesture)
@leoiphonedev
leoiphonedev / UITapGesture.swift
Last active November 28, 2023 12:45
Extension for UITapGesture that contains a function to detect range of particular text in UILabel's text.
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)
@kuratowsky
kuratowsky / gist:6e027fd2270d5bf5ac4ee41764e4bfdb
Last active June 4, 2023 09:51 — forked from shekarsiri/gist:2822b0958e967860ed07d2d63529ffeb
UITextField accept only numbers to certain limits (Swift 5 Tested.)
// 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))