Skip to content

Instantly share code, notes, and snippets.

View dimkagithub's full-sized avatar

Dmitry dimkagithub

View GitHub Profile
@dimkagithub
dimkagithub / Double extension.swift
Last active November 6, 2021 06:52
Double extension
extension Double {
var roundTo: Double { (self * 100).rounded() / 100 }
}
@dimkagithub
dimkagithub / UIColor extension.swift
Last active November 6, 2021 06:52
UIColor extension
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) )
}
@dimkagithub
dimkagithub / UIIMageView extension.swift
Last active November 6, 2021 06:52
UIIMageView extension
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
@dimkagithub
dimkagithub / CustomDateFormatter.swift
Last active November 6, 2021 06:51
CustomDateFormatter
import Foundation
public extension DateFormatter {
enum DateFormat {
case defaultFormat
// Add here your date formats
fileprivate var dateFormat: String {
switch self {
@dimkagithub
dimkagithub / System Boot Time.swift
Created November 1, 2021 17:51
System Boot Time
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)
}
@dimkagithub
dimkagithub / UIView Extension.swift
Created November 2, 2021 05:53
UIView Extension
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
}
}
@dimkagithub
dimkagithub / UIIMageView Extension.swift
Last active November 6, 2021 06:51
UIIMageView Extension
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")
}
@dimkagithub
dimkagithub / UIImageView Extension.swift
Last active November 6, 2021 06:51
UIImageView Extension
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
@dimkagithub
dimkagithub / UIView Extension.swift
Created November 6, 2021 04:10
UIView Extension
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")
}
}
@dimkagithub
dimkagithub / UserDefaults.swift
Last active November 7, 2021 20:33
UserDefaults
private var variable: Bool {
get {
return UserDefaults.standard.bool(forKey: "variableKey")
}
set {
UserDefaults.standard.setValue(newValue, forKey: "variableKey")
UserDefaults.standard.synchronize()
}
}