Dra*_*rok 18 ios swift swiftui
给出以下示例代码:
struct ActivityIndicatorView : UIViewRepresentable {
var style: UIActivityIndicatorView.Style = .medium
func makeUIView(context: UIViewRepresentableContext<ActivityIndicatorView>) -> UIActivityIndicatorView {
return UIActivityIndicatorView(style: style)
}
func updateUIView(_ uiView: UIActivityIndicatorView, context: UIViewRepresentableContext<ActivityIndicatorView>) {
uiView.color = UIColor.white // how would I set this to the current .foregroundColor value?
}
}
Run Code Online (Sandbox Code Playgroud)
我如何找出当前值.foregroundColor(…)以正确呈现我的 UIView?
我已经阅读了这个问题,但这是从外部检查 ModifiedContent 的角度来看的,而不是包装的 View。
无法访问前景色,但您可以访问配色方案并据此确定活动指示器的颜色:
struct ActivityIndicatorView : UIViewRepresentable {
@Environment(\.colorScheme) var colorScheme: ColorScheme
//...
func updateUIView(_ uiView: UIActivityIndicatorView, context: UIViewRepresentableContext<ActivityIndicatorView>) {
switch colorScheme {
case .dark:
uiView.color = .white
case .light:
uiView.color = .black
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1579 次 |
| 最近记录: |