123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- import Foundation
- extension UIImageView {
-
- @objc func avatar(roundness: CGFloat = 2, borderWidth: CGFloat = 1, borderColor: UIColor = NCBrandColor.shared.avatarBorder, backgroundColor: UIColor = .clear) {
-
- layer.cornerRadius = bounds.width / roundness
- layer.borderWidth = borderWidth
- layer.borderColor = borderColor.cgColor
- layer.backgroundColor = backgroundColor.cgColor
- clipsToBounds = true
-
- let path = UIBezierPath(roundedRect: bounds.insetBy(dx: 0.5, dy: 0.5), cornerRadius: bounds.width / roundness)
- let mask = CAShapeLayer()
-
- mask.path = path.cgPath
- layer.mask = mask
- }
-
- func clearLayerMask() {
-
- layer.cornerRadius = 0
- layer.borderWidth = 0
- layer.borderColor = nil
- layer.backgroundColor = nil
-
- clipsToBounds = false
-
- mask = nil
- layer.mask = nil
- }
- }
|