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.
LeCountdown/LeCountdown/Views/Reusable/ViewModifiers.swift

50 lines
1.1 KiB

//
// ViewModifiers.swift
// LeCountdown
//
// Created by Laurent Morvillier on 27/01/2023.
//
import Foundation
import SwiftUI
extension View {
func roundedCorner(selected: Bool) -> some View {
modifier(RoundedCornerSelection(selected: selected))
}
func cornerRadius(_ radius: CGFloat, corners: UIRectCorner) -> some View {
clipShape( RoundedCorner(radius: radius, corners: corners) )
}
}
struct RoundedCornerSelection: ViewModifier {
var selected: Bool
func body(content: Content) -> some View {
if selected {
content
.overlay(
RoundedRectangle(cornerRadius: 40)
.stroke(Color.blue, lineWidth: 5)
)
} else {
content
}
}
}
struct RoundedCorner: Shape {
var radius: CGFloat = .infinity
var corners: UIRectCorner = .allCorners
func path(in rect: CGRect) -> Path {
let path = UIBezierPath(roundedRect: rect, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
return Path(path.cgPath)
}
}