You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.3 KiB

6 years ago
6 years ago
6 years ago
6 years ago
  1. //
  2. // UIViewExtension.swift
  3. // GMERemittance
  4. //
  5. // Created by Fm-user on 12/23/17.
  6. // Copyright © 2017 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import Foundation
  9. import UIKit
  10. import VisualEffectView
  11. extension UIView {
  12. func roundCorners(_ corners: UIRectCorner, radius: CGFloat, borderColor: UIColor?, borderWidth: CGFloat?) {
  13. let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
  14. let mask = CAShapeLayer()
  15. mask.frame = self.bounds
  16. mask.path = path.cgPath
  17. self.layer.mask = mask
  18. if borderWidth != nil {
  19. addBorder(mask, borderWidth: borderWidth!, borderColor: borderColor!)
  20. }
  21. }
  22. private func addBorder(_ mask: CAShapeLayer, borderWidth: CGFloat, borderColor: UIColor) {
  23. let borderLayer = CAShapeLayer()
  24. borderLayer.path = mask.path
  25. borderLayer.fillColor = UIColor.clear.cgColor
  26. borderLayer.strokeColor = borderColor.cgColor
  27. borderLayer.lineWidth = borderWidth
  28. borderLayer.frame = bounds
  29. layer.addSublayer(borderLayer)
  30. }
  31. func rounded() {
  32. self.layer.cornerRadius = self.frame.height / 2
  33. }
  34. func addBlur() {
  35. let visualEffectView = VisualEffectView(frame: self.frame)
  36. visualEffectView.colorTint = .clear
  37. visualEffectView.colorTintAlpha = 0.2
  38. visualEffectView.blurRadius = 3
  39. visualEffectView.scale = 1
  40. visualEffectView.isUserInteractionEnabled = false
  41. self.addSubview(visualEffectView)
  42. }
  43. }
  44. extension UIView {
  45. func fadeIn(duration: TimeInterval = 1.0, delay: TimeInterval = 0.0, completion: @escaping ((Bool) -> Void) = {(finished: Bool) -> Void in}) {
  46. UIView.animate(withDuration: duration, delay: delay, options: UIViewAnimationOptions.curveEaseIn, animations: {
  47. self.alpha = 1.0
  48. }, completion: completion)
  49. }
  50. func fadeOut(duration: TimeInterval = 1.0, delay: TimeInterval = 3.0, completion: @escaping (Bool) -> Void = {(finished: Bool) -> Void in}) {
  51. UIView.animate(withDuration: duration, delay: delay, options: UIViewAnimationOptions.curveEaseIn, animations: {
  52. self.alpha = 0.0
  53. }, completion: completion)
  54. }
  55. }