26 lines
709 B
Swift
26 lines
709 B
Swift
import SwiftUI
|
||
import AVKit
|
||
|
||
#if os(iOS)
|
||
/// AirPlay 投屏按钮 — 封装 AVRoutePickerView
|
||
/// 点击后弹出系统 AirPlay 设备选择面板
|
||
struct AirPlayButton: UIViewRepresentable {
|
||
|
||
/// 按钮颜色(默认白色)
|
||
var tintColor: UIColor = .white
|
||
|
||
func makeUIView(context: Context) -> AVRoutePickerView {
|
||
let picker = AVRoutePickerView()
|
||
picker.tintColor = tintColor
|
||
picker.activeTintColor = UIColor.systemBlue
|
||
// 使按钮在深色背景下可见
|
||
picker.backgroundColor = .clear
|
||
return picker
|
||
}
|
||
|
||
func updateUIView(_ uiView: AVRoutePickerView, context: Context) {
|
||
uiView.tintColor = tintColor
|
||
}
|
||
}
|
||
#endif
|