Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Foundation
- import UIKit
- extension UIColor {
- static let kAppColor = UIColor(red:0.0/255.0, green:151.0/255.0 ,blue:70.0/255.0, alpha:1.00)
- static let kDarkBlue = UIColor(red:0.0/255.0, green:116.0/255.0 ,blue:187.0/255.0, alpha:1.00)
- static let kRed = UIColor(red:242.0/255.0, green:37.0/255.0 ,blue:10.0/255.0, alpha:1.00)
- static let kDarkText = UIColor(red:38.0/255.0, green:38.0/255.0 ,blue:38.0/255.0, alpha:1.00)
- static let kLightBlue = UIColor(red:65.0/255.0, green:171.0/255.0 ,blue:248.0/255.0, alpha:1.00)
- static let kGray = UIColor(red:149.0/255.0, green:152.0/255.0 ,blue:154.0/255.0, alpha:1.00)
- convenience init(red: Int, green: Int, blue: Int) {
- assert(red >= 0 && red <= 255, "Invalid red component")
- assert(green >= 0 && green <= 255, "Invalid green component")
- assert(blue >= 0 && blue <= 255, "Invalid blue component")
- self.init(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: 1.0)
- }
- convenience init(netHex:Int) {
- self.init(red:(netHex >> 16) & 0xff, green:(netHex >> 8) & 0xff, blue:netHex & 0xff)
- }
- }
- extension UIFont {
- static func regular(withSize size: CGFloat) -> UIFont {
- return UIFont(name: "Montserrat-Regular", size: size)!
- }
- static func medium(withSize size: CGFloat) -> UIFont {
- return UIFont(name: "Montserrat-Medium", size: size)!
- }
- static func bold(withSize size: CGFloat) -> UIFont {
- return UIFont(name: "Montserrat-Bold", size: size)!
- }
- static func semiBold(withSize size: CGFloat) -> UIFont {
- return UIFont(name: "Montserrat-SemiBold", size: size)!
- }
- static func light(withSize size: CGFloat) -> UIFont {
- return UIFont(name: "Montserrat-Light", size: size)!
- }
- }
- extension UIViewController {
- func getStotyboardId() -> String { return String(describing: self) }
- func getClassName() -> String {
- return NSStringFromClass(self.classForCoder).components(separatedBy:".").last!
- }
- }
- let imageCache = NSCache<AnyObject, AnyObject>()
- extension UIImageView {
- func downloadImageWithUrlString(urlString: String) -> Void {
- if urlString.count == 0 { return }
- self.image = nil
- if let cachedImage = imageCache.object(forKey: urlString as AnyObject) as? UIImage {
- self.image = cachedImage
- return
- }
- let request = URLRequest(url: URL(string: urlString)!)
- let dataTask = URLSession.shared.dataTask(with: request) {data, response, error in
- if error != nil { return }
- DispatchQueue.main.async {
- let downloadedImage = UIImage(data: data!)
- if let image = downloadedImage {
- imageCache.setObject(image, forKey: urlString as AnyObject)
- self.image = UIImage(data: data!)
- }
- }
- }
- dataTask.resume()
- }
- }
- extension UILabel {
- var optimalHeight : CGFloat {
- get {
- let label = UILabel(frame: CGRect(x: 0, y: 0, width: self.bounds.width, height: CGFloat.greatestFiniteMagnitude))
- label.numberOfLines = 0
- label.lineBreakMode = NSLineBreakMode.byWordWrapping
- label.font = self.font
- label.text = self.text
- label.sizeToFit()
- return label.frame.height
- }
- }
- }
- extension Date {
- func daysBetween(date: Date) -> Int {
- return Date.daysBetween(start: self, end: date)
- }
- static func daysBetween(start: Date, end: Date) -> Int {
- let calendar = Calendar.current
- // Replace the hour (time) of both dates with 00:00
- let date1 = calendar.startOfDay(for: start)
- let date2 = calendar.startOfDay(for: end)
- let a = calendar.dateComponents([.day], from: date1, to: date2)
- return a.value(for: .day)!
- }
- static func dateFromNow(years: Int) -> Date {
- let currentCalendar = Calendar.current
- let now = Date()
- var components: DateComponents = DateComponents()
- components.year = years
- let dateFromNow: Date = currentCalendar.date(byAdding: components, to: now)!
- return dateFromNow
- }
- }
- extension UIButton {
- func makeRoundedShadow() {
- layer.cornerRadius = 5
- layer.masksToBounds = false
- layer.shadowOffset = CGSize(width: 5, height: 5)
- layer.shadowColor = UIColor.lightGray.cgColor
- layer.shadowRadius = 3
- layer.shadowOpacity = 0.7
- }
- }
Add Comment
Please, Sign In to add comment