99 lines
2.8 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import SwiftUI
/// 便
/// 使
/// CircleView(diameter: 24, color: .orange, stroke: .white, lineWidth: 2)
public struct CircleView: View {
public var diameter: CGFloat
public var color: Color
public var stroke: Color? = nil
public var lineWidth: CGFloat = 1
public init(
diameter: CGFloat,
color: Color = .black,
stroke: Color? = nil,
lineWidth: CGFloat = 1
) {
self.diameter = diameter
self.color = color
self.stroke = stroke
self.lineWidth = lineWidth
}
public var body: some View {
Group {
if let stroke = stroke, lineWidth > 0 {
Circle()
.fill(color)
.overlay(
Circle().stroke(stroke, lineWidth: lineWidth)
)
} else {
Circle().fill(color)
}
}
.frame(width: diameter, height: diameter)
.accessibilityHidden(true)
}
}
///
public struct CircleRow: View {
public var count: Int
public var diameter: CGFloat
public var color: Color
public var spacing: CGFloat
public init(
count: Int,
diameter: CGFloat,
color: Color = .black,
spacing: CGFloat = 8
) {
self.count = count
self.diameter = diameter
self.color = color
self.spacing = spacing
}
public var body: some View {
HStack(spacing: spacing) {
ForEach(0..<(max(0, count)), id: \.self) { _ in
CircleView(diameter: diameter, color: color)
}
}
.accessibilityElement(children: .ignore)
}
}
#if DEBUG
struct CircleView_Previews: PreviewProvider {
static var previews: some View {
Group {
CircleView(diameter: 40, color: .black, stroke: .white, lineWidth: 2)
.padding()
.previewDisplayName("Single Circle")
ZStack {
Color(.black)
HStack {
RoundedRectangle(cornerRadius: 12, style: .continuous)
.fill(.white)
.shadow(color: Color.black.opacity(0.06), radius: 6, x: 0, y: 2)
.overlay(
HStack {
CircleRow(count: 6, diameter: 10, color: .black, spacing: 6)
}
.padding(.horizontal, 16)
)
.frame(height: 56)
.padding()
}
}
.previewDisplayName("Circle Row")
}
.previewLayout(.sizeThatFits)
}
}
#endif