✨Custom Circle
在螢幕上畫點,可設定顏色、半徑、外框顏色、透明度等。
Last updated
在螢幕上畫點,可設定顏色、半徑、外框顏色、透明度等。
Last updated
import SwiftUI
import Extensions // for 🌀View + .frame(_:_:)
// 📦 Point
public struct Point: View {
// properties
let color : Color
let radius : CGFloat
let strokeColor: Color
let opacity : Double
// init
public init(
_ radius : CGFloat = 10,
color : Color = .red,
strokeColor: Color = .black,
opacity : Double = 0.8
) {
self.radius = radius
self.color = color
self.strokeColor = strokeColor
self.opacity = opacity
}
// content
public var body: some View {
ZStack {
Circle()
.fill(color)
.frame(radius * 2, radius * 2)
.opacity(opacity)
.overlay(Circle().stroke(strokeColor)) // outline
.shadow(radius: 8)
}
}
}
HStack(spacing: 10) {
Point()
Point(15, color: .blue)
Point(20, color: .black, strokeColor: Color(white: 0.8), opacity: 0.3)
ZStack {
Point(30, color: .green, opacity: 0.3)
Point(color: .orange, opacity: 0.6)
}
} // HStack (container)
.frame(200, 100)
.grids(.black)
.background(Color.gray)
Helper Shapes has more handy shapes.