UIViewExtension.swift 825 B

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