Skip to content

Instantly share code, notes, and snippets.

@faganello60
Created May 7, 2020 22:29
Show Gist options
  • Save faganello60/fd45a4c97b3b237a6e7b27792f02e61b to your computer and use it in GitHub Desktop.
Save faganello60/fd45a4c97b3b237a6e7b27792f02e61b to your computer and use it in GitHub Desktop.
public extension UIView {
func roundCorners(_ corners: UIRectCorner, radius: CGFloat) {
let roundedLayer = CAShapeLayer()
roundedLayer.path = UIBezierPath(
roundedRect: bounds,
byRoundingCorners: corners,
cornerRadii: CGSize(width: radius, height: radius)
).cgPath
layer.mask = roundedLayer
}
func fadeTo(
_ alpha: CGFloat,
duration: TimeInterval = 0.3,
delay: TimeInterval = 0,
completion: (() -> Void)? = nil) {
UIView.animate(
withDuration: duration,
delay: delay,
options: .curveEaseInOut,
animations: {
self.alpha = alpha
},
completion: nil
)
DispatchQueue.main.asyncAfter(deadline: .now() + duration) {
completion?()
}
}
func fadeIn(duration: TimeInterval = 0.3, delay: TimeInterval = 0, completion: (() -> Void)? = nil) {
fadeTo(1, duration: duration, delay: delay, completion: completion)
}
func fadeOut(duration: TimeInterval = 0.3, delay: TimeInterval = 0, completion: (() -> Void)? = nil) {
fadeTo(0, duration: duration, delay: delay, completion: completion)
}
}
//--------------------------------------------------
// MARK: - UIViewController
//--------------------------------------------------
public extension UIViewController {
func presentBottomSheet(_ bottomSheet: BottomSheetViewController, completion: (() -> Void)?) {
self.present(bottomSheet, animated: false, completion: completion)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment