Runt
2025-06-27 e21b1c797955a231f2bcf71818e0259fbb6aeba1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//
//  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)
    }
}