//
|
// IconMic.swift
|
// LiveProject
|
//
|
// Created by 倪路朋 on 6/27/25.
|
//
|
import SwiftUI
|
|
struct IconMicShape: Shape {
|
func path(in rect: CGRect) -> Path {
|
var path = Path()
|
|
// 计算容器高度(麦克风主体 + 支架 + 底座 + 一点留白)
|
let micHeight = rect.height * 0.5
|
let stemHeight = rect.height * 0.1
|
let baseHeight = rect.height * 0.02
|
let containerHeight = micHeight + stemHeight + baseHeight
|
|
// 计算顶部偏移量,确保垂直居中
|
let topOffset = (rect.height - containerHeight) / 2
|
|
// 主体:麦克风(居中)
|
let micWidth = rect.width * 0.3
|
let micRect = CGRect(
|
x: rect.midX - micWidth / 2,
|
y: topOffset,
|
width: micWidth,
|
height: micHeight
|
)
|
path.addRoundedRect(in: micRect, cornerSize: CGSize(width: micWidth / 2, height: micWidth / 2))
|
|
// 支架
|
let stemTop = CGPoint(x: rect.midX, y: micRect.maxY)
|
let stemBottom = CGPoint(x: rect.midX, y: stemTop.y + stemHeight)
|
path.move(to: stemTop)
|
path.addLine(to: stemBottom)
|
|
// 底座
|
let baseWidth = rect.width * 0.3
|
path.move(to: CGPoint(x: rect.midX - baseWidth / 2, y: stemBottom.y))
|
path.addLine(to: CGPoint(x: rect.midX + baseWidth / 2, y: stemBottom.y))
|
|
return path
|
}
|
}
|
struct IconMic: View {
|
var color: Color = .white
|
var size: CGSize = CGSize(width: 20, height:30)
|
var lineWidth: CGFloat = 2.0
|
|
var body: some View {
|
IconMicShape()
|
.stroke(color, lineWidth: lineWidth)
|
.frame(width: size.width, height: size.height)
|
}
|
}
|
|
|
struct IconMic_Previews : PreviewProvider{
|
static var previews: some View {
|
IconMic(color: .black).background(.red)
|
}
|
}
|