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.

43 lines
1.2 KiB

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. extension UIView {
  11. func roundCorners(_ corners: UIRectCorner, radius: CGFloat, borderColor: UIColor?, borderWidth: CGFloat?) {
  12. let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
  13. let mask = CAShapeLayer()
  14. mask.frame = self.bounds
  15. mask.path = path.cgPath
  16. self.layer.mask = mask
  17. if borderWidth != nil {
  18. addBorder(mask, borderWidth: borderWidth!, borderColor: borderColor!)
  19. }
  20. }
  21. private func addBorder(_ mask: CAShapeLayer, borderWidth: CGFloat, borderColor: UIColor) {
  22. let borderLayer = CAShapeLayer()
  23. borderLayer.path = mask.path
  24. borderLayer.fillColor = UIColor.clear.cgColor
  25. borderLayer.strokeColor = borderColor.cgColor
  26. borderLayer.lineWidth = borderWidth
  27. borderLayer.frame = bounds
  28. layer.addSublayer(borderLayer)
  29. }
  30. func rounded() {
  31. self.layer.cornerRadius = self.frame.height / 2
  32. }
  33. }