import UIKit /// 按体验网页的矢量路径绘制空境库与订单素材库的选择图标。 @MainActor enum MaterialSelectionIcon { /// 统一选择控件蓝色。 static let primary = UIColor(hex: 0x066BFF) /// 绘制空境库的空心圆或带不透明白色勾的实心圆,支持不同尺寸与禁用透明度。 static func scenicImage(selected: Bool, size: CGFloat, tint: UIColor, opacity: CGFloat = 1) -> UIImage { UIGraphicsImageRenderer(size: CGSize(width: size, height: size)).image { context in let canvas = context.cgContext canvas.setAlpha(opacity) canvas.beginTransparencyLayer(auxiliaryInfo: nil) defer { canvas.endTransparencyLayer() } canvas.scaleBy(x: size / 24, y: size / 24) let radius: CGFloat = selected ? 10 : 9 let circle = UIBezierPath(ovalIn: CGRect(x: 12 - radius, y: 12 - radius, width: radius * 2, height: radius * 2)) if selected { tint.setFill() circle.fill() UIColor.white.setStroke() let check = UIBezierPath() check.move(to: CGPoint(x: 9, y: 12)) check.addLine(to: CGPoint(x: 11, y: 14)) check.addLine(to: CGPoint(x: 15, y: 10)) check.lineWidth = 2 check.lineCapStyle = .round check.lineJoinStyle = .round check.stroke() } else { tint.setStroke() circle.lineWidth = 2 circle.stroke() } }.withRenderingMode(.alwaysOriginal) } /// 绘制订单素材库的线框圆和勾;卡片可附圆形底色,文字按钮保持透明背景。 static func orderImage(selected: Bool, size: CGFloat, tint: UIColor, includesBackground: Bool, opacity: CGFloat = 1) -> UIImage { UIGraphicsImageRenderer(size: CGSize(width: size, height: size)).image { context in let canvas = context.cgContext canvas.setAlpha(opacity) canvas.beginTransparencyLayer(auxiliaryInfo: nil) defer { canvas.endTransparencyLayer() } canvas.scaleBy(x: size / 15, y: size / 15) if includesBackground { (selected ? tint : UIColor.white).setFill() UIBezierPath(ovalIn: CGRect(x: 0, y: 0, width: 15, height: 15)).fill() } let stroke = includesBackground && selected ? UIColor.white : tint stroke.setStroke() let center: CGFloat = 7.4999 let radius: CGFloat = 6.1478 let circle = UIBezierPath(ovalIn: CGRect(x: center - radius, y: center - radius, width: radius * 2, height: radius * 2)) circle.lineWidth = 0.95 circle.stroke() if selected { let check = UIBezierPath() check.move(to: CGPoint(x: 5, y: 8.13735)) check.addLine(to: CGPoint(x: 6.58333, y: 9.75)) check.addLine(to: CGPoint(x: 9.75, y: 5.25)) check.lineWidth = 1 check.lineCapStyle = .round check.lineJoinStyle = .round check.stroke() } }.withRenderingMode(.alwaysOriginal) } }