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
func resizeImageWith(image: UIImage, newSize: CGSize) -> UIImage { | |
let horizontalRatio = newSize.width / image.size.width | |
let verticalRatio = newSize.height / image.size.height | |
let ratio = max(horizontalRatio, verticalRatio) | |
let newSize = CGSize(width: image.size.width * ratio, height: image.size.height * ratio) | |
var newImage: UIImage | |
if #available(iOS 10.0, *) { |
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
func JSONStringify(value: AnyObject, prettyPrinted: Bool = true) -> String { | |
let options = prettyPrinted ? JSONSerialization.WritingOptions.prettyPrinted : nil | |
if JSONSerialization.isValidJSONObject(value) { | |
do { | |
let data = try JSONSerialization.data(withJSONObject: value, options: options!) | |
if let string = NSString(data: data, encoding: String.Encoding.utf8.rawValue) { | |
return string as String | |
} | |
} catch { | |
return "" |
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
import UIKit | |
extension UIView { | |
func roundCorners(_ corners: UIRectCorner, radius: CGFloat) { | |
let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius)) | |
let mask = CAShapeLayer() | |
mask.path = path.cgPath | |
self.layer.mask = mask | |
} |
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
import UIKit | |
// creating a color object | |
extension UIColor { | |
static let foodBulbGreen = UIColor(r: 47, g: 212, b: 128, a: 1) | |
static let foodBulbOrange = UIColor(r: 255, g: 130, b: 98, a: 1) | |
} | |
// usage: UIColor.foodBulbGreen |
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
import UIKit | |
@IBDesignable class CustomUITextField: UITextField { | |
@IBInspectable var cornerRadius: CGFloat = 0 { | |
didSet { | |
layer.cornerRadius = cornerRadius | |
} | |
} |