UIViewExtension.swift 853 B

1234567891011121314151617181920212223242526
  1. // LoopFollow
  2. // UIViewExtension.swift
  3. // Created by Jose Paredes.
  4. import Foundation
  5. import UIKit
  6. extension UIView {
  7. enum ViewSide {
  8. case Left, Right, Top, Bottom
  9. }
  10. func addBorder(toSide side: ViewSide, withColor color: CGColor, andThickness thickness: CGFloat) {
  11. let border = CALayer()
  12. border.backgroundColor = color
  13. switch side {
  14. case .Left: border.frame = CGRect(x: 0, y: 0, width: thickness, height: frame.height)
  15. case .Right: border.frame = CGRect(x: frame.width - thickness, y: 0, width: thickness, height: frame.height)
  16. case .Top: border.frame = CGRect(x: 0, y: 0, width: frame.width, height: thickness)
  17. case .Bottom: border.frame = CGRect(x: 0, y: frame.height - thickness, width: frame.width, height: thickness)
  18. }
  19. layer.addSublayer(border)
  20. }
  21. }