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 Double { | |
var roundTo: Double { (self * 100).rounded() / 100 } | |
} |
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 UIColor { | |
func setLighter(by percentage: CGFloat = 30.0) -> UIColor? { | |
return self.adjust(by: abs(percentage) ) | |
} | |
func setDarker(by percentage: CGFloat = 30.0) -> UIColor? { | |
return self.adjust(by: -1 * abs(percentage) ) | |
} | |
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 UIImageView { | |
func setImageShadow() { | |
super.layoutSubviews() | |
self.layer.shadowColor = UIColor.lightGray.cgColor | |
self.layer.shadowOpacity = 1.0 | |
self.layer.shadowRadius = 5.0 | |
self.layer.shadowOffset = CGSize(width: 0.0, height: 0.0) | |
self.layer.cornerRadius = bounds.height / 2 | |
self.clipsToBounds = false |
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 Foundation | |
public extension DateFormatter { | |
enum DateFormat { | |
case defaultFormat | |
// Add here your date formats | |
fileprivate var dateFormat: String { | |
switch self { |
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 bootTime() -> Date? { | |
var tv = timeval() | |
var tvSize = MemoryLayout<timeval>.size | |
let err = sysctlbyname("kern.boottime", &tv, &tvSize, nil, 0); | |
guard err == 0, tvSize == MemoryLayout<timeval>.size else { | |
return nil | |
} | |
return Date(timeIntervalSince1970: Double(tv.tv_sec) + Double(tv.tv_usec) / 1_000_000.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
extension UIView { | |
func roundCorners(corners: UIRectCorner, radius: CGFloat) { | |
let path = UIBezierPath(roundedRect: bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius)) | |
let mask = CAShapeLayer() | |
mask.path = path.cgPath | |
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
extension UIImageView { | |
func rotate() { | |
let rotation : CABasicAnimation = CABasicAnimation(keyPath: "transform.rotation.x") | |
rotation.toValue = NSNumber(value: Double.pi * 2) | |
rotation.duration = 2 | |
rotation.isCumulative = true | |
rotation.repeatCount = Float.greatestFiniteMagnitude | |
self.layer.add(rotation, forKey: "rotationAnimation") | |
} |
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 UIImageView { | |
func setImageShadow() { | |
super.layoutSubviews() | |
self.layer.shadowColor = UIColor.lightGray.cgColor | |
self.layer.shadowOpacity = 1.0 | |
self.layer.shadowRadius = 5.0 | |
self.layer.shadowOffset = CGSize(width: 0.0, height: 0.0) | |
self.layer.cornerRadius = bounds.height / 2 | |
self.clipsToBounds = false |
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 UIView{ | |
func rotate() { | |
let rotation : CABasicAnimation = CABasicAnimation(keyPath: "transform.rotation.x") | |
rotation.toValue = NSNumber(value: Double.pi * 2) | |
rotation.duration = 1 | |
rotation.isCumulative = true | |
rotation.repeatCount = Float.greatestFiniteMagnitude | |
self.layer.add(rotation, forKey: "rotationAnimation") | |
} | |
} |
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
private var variable: Bool { | |
get { | |
return UserDefaults.standard.bool(forKey: "variableKey") | |
} | |
set { | |
UserDefaults.standard.setValue(newValue, forKey: "variableKey") | |
UserDefaults.standard.synchronize() | |
} | |
} |
OlderNewer