.border(), .borderLeft() ...
import SwiftUI
// ๐View + .border(width, color, dash)
extension View {
/// # Border Line
/// draws solid line if `dash` is omitted.
/// ## โญ๏ธ Examples:
/// - `view.border() == view.border(1)`
/// - `view.border(2, .red)`
/// - `view.border(dash: [3])`
/// - `view.border(1, .pink, dash: [5])`
@ViewBuilder public func border(
_ width: CGFloat = 1,
_ color: Color = .blue,
dash : [CGFloat]? = nil
) -> some View {
if dash != nil {
self.overlay(
Rectangle()
.stroke(color, style: .init(lineWidth: width, dash: dash!))
)
} else {
self.border(color, width: width)
}
}
}
extension View {
/// โญ๏ธ left border
func borderLeft(color: Color = .red, width: CGFloat = 1) -> some View {
overlay(VLine(color: color, width: width), alignment: .leading)
}
/// โญ๏ธ bottom border
func borderBottom(color: Color = .red, width: CGFloat = 1) -> some View {
overlay(HLine(color: color, width: width), alignment: .bottom)
}
/// โญ๏ธ base line
func baseLine() -> some View {
overlay(HLine(), alignment: Alignment(
horizontal: .center,
vertical: .firstTextBaseline
))
}
}
SwiftUI โฉ View โฉ Styling .border(_:width:)
Last updated