Skip to content

Instantly share code, notes, and snippets.

View johncodeos's full-sized avatar
:octocat:

John johncodeos

:octocat:
View GitHub Profile
@johncodeos
johncodeos / FixNavigationBarColor.swift
Last active January 22, 2022 11:38
Fix for the transparent/gray navigation bar in iOS 15
// For UIKit project
override func viewDidLoad() {
super.viewDidLoad()
self.title = "Demo App"
self.navigationController?.navigationBar.isTranslucent = false
self.navigationController?.navigationBar.tintColor = .white
self.navigationController?.navigationBar.barTintColor = .red
if #available(iOS 13.0, *) {
let appearance = UINavigationBarAppearance()
appearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
@johncodeos
johncodeos / Extensions.swift
Last active January 19, 2022 09:02
Convert String date to Date
extension String {
func iso8601Value() -> Date? {
let theDate = self
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZ"
let date = formatter.date(from: theDate as String)
return date
}
@johncodeos
johncodeos / Extensions.swift
Last active January 20, 2022 11:57
Convert HEX color code to UIColor
extension UIColor {
static func colorFromHex(_ hex: String) -> UIColor {
var hexString = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
if hexString.hasPrefix("#") {
hexString.remove(at: hexString.startIndex)
}
if hexString.count != 6 {
return UIColor.magenta
}
@johncodeos
johncodeos / htmltagsinswift.swift
Created May 1, 2016 10:49
use HTML tags in uitextview
extension NSData {
var attributedString: NSAttributedString? {
do {
return try NSAttributedString(data: self, options:[NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: NSUTF8StringEncoding], documentAttributes: nil)
} catch let error as NSError {
print(error.localizedDescription)
}
return nil
}
}