1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-15 06:40:32 +05:30
yattee/Extensions/View+Borders.swift

40 lines
1.4 KiB
Swift
Raw Normal View History

import Foundation
import SwiftUI
extension View {
func borderTop(height: Double, color: Color = Color(white: 0.7, opacity: 1)) -> some View {
verticalEdgeBorder(.top, height: height, color: color)
}
func borderBottom(height: Double, color: Color = Color(white: 0.7, opacity: 1)) -> some View {
verticalEdgeBorder(.bottom, height: height, color: color)
}
2021-11-28 20:07:55 +05:30
func borderLeading(width: Double, color: Color = Color(white: 0.7, opacity: 1)) -> some View {
horizontalEdgeBorder(.leading, width: width, color: color)
}
func borderTrailing(width: Double, color: Color = Color(white: 0.7, opacity: 1)) -> some View {
horizontalEdgeBorder(.trailing, width: width, color: color)
}
private func verticalEdgeBorder(_ edge: Alignment, height: Double, color: Color) -> some View {
2022-11-19 05:28:21 +05:30
overlay(
Rectangle()
.frame(width: nil, height: height, alignment: .top)
.foregroundColor(color)
.ignoresSafeArea(.all, edges: .horizontal),
alignment: edge
)
2021-11-28 20:07:55 +05:30
}
private func horizontalEdgeBorder(_ edge: Alignment, width: Double, color: Color) -> some View {
2022-11-19 05:28:21 +05:30
overlay(
Rectangle()
.frame(width: width, height: nil, alignment: .leading)
.foregroundColor(color),
alignment: edge
)
}
}