[英]How to change UITextField size inside UIViewRepresentable in SwiftUI
[英]In SwiftUI, how can I access the current value of .foregroundColor and other modifiers inside my UIViewRepresentable?
给出以下示例代码:
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?
}
}
如何找出.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
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.