//
|
// IconCamera.swift
|
// LiveProject
|
//
|
// Created by 倪路朋 on 6/27/25.
|
//
|
|
import SwiftUI
|
|
struct IconCameraShape: Shape {
|
func path(in rect: CGRect) -> Path {
|
var path = Path()
|
|
// 比例参数
|
let cornerRadius = rect.height * 0.1
|
let bodyInset = rect.height * 0.1
|
let lensDiameter = rect.height * 0.3
|
let flashSize = CGSize(width: rect.width * 0.08, height: rect.height * 0.08)
|
|
// 相机机身(主圆角矩形)
|
let bodyRect = rect.insetBy(dx: 0, dy: bodyInset)
|
path.addRoundedRect(in: bodyRect, cornerSize: CGSize(width: cornerRadius, height: cornerRadius))
|
|
// 镜头(中间大圆)
|
let lensOrigin = CGPoint(
|
x: rect.midX - lensDiameter / 2,
|
y: rect.midY - lensDiameter / 2
|
)
|
let lensRect = CGRect(origin: lensOrigin, size: CGSize(width: lensDiameter, height: lensDiameter))
|
path.addEllipse(in: lensRect)
|
|
// 闪光灯(机身内的小圆点)
|
let flashOrigin = CGPoint(
|
x: bodyRect.maxX - flashSize.width * 1.5,
|
y: bodyRect.minY + flashSize.height * 1.5
|
)
|
let flashRect = CGRect(origin: flashOrigin, size: flashSize)
|
path.addEllipse(in: flashRect)
|
|
return path
|
}
|
}
|
|
struct IconCamera: View {
|
var color: Color = .white
|
var size: CGSize = CGSize(width: 20, height:20)
|
var lineWidth: CGFloat = 2.0
|
|
var body: some View {
|
IconCameraShape()
|
.stroke(color, lineWidth: lineWidth)
|
.frame(width: size.width, height: size.height)
|
}
|
}
|
|
struct IconCamera_Previews : PreviewProvider{
|
static var previews: some View {
|
IconCamera(color: .black).background(.red)
|
}
|
}
|