patbef-iOS/Befund/Core/Extensions/ViewExtension.swift

37 lines
1.0 KiB
Swift

//
// ViewExtension.swift
// Befund
//
// Created by Irakli Abetschkhrischwili on 27.05.22.
// Copyright © 2022 MVZ Dr. Stein und Kollegen. All rights reserved.
//
import Foundation
import UIKit
extension UIView
{
/**
* Creates a dashed border for UIView
*/
func addDashedBorder()
{
let color = UIColor.white.cgColor
let shapeLayer:CAShapeLayer = CAShapeLayer()
let frameSize = self.frame.size
let shapeRect = CGRect(x: 0, y: 0, width: frameSize.width, height: frameSize.height)
shapeLayer.bounds = shapeRect
shapeLayer.position = CGPoint(x: frameSize.width/2, y: frameSize.height/2)
shapeLayer.fillColor = UIColor.clear.cgColor
shapeLayer.strokeColor = color
shapeLayer.lineWidth = 2
shapeLayer.lineJoin = CAShapeLayerLineJoin.round
shapeLayer.lineDashPattern = [6,3]
shapeLayer.path = UIBezierPath(roundedRect: shapeRect, cornerRadius: 4).cgPath
self.layer.addSublayer(shapeLayer)
}
}