[英]How can I access modifiers of a view in SwiftUI?
Assume I have a View
with an Image
that has a shadow
property: 假设我有一个
View
与Image
具有shadow
属性:
struct ContentView: View {
var body: some View {
let myImage = Image("turtlerock").shadow(radius: 10)
return myImage
}
}
Now imagine I want to access the value of the shadow radius. 现在想象一下我想要访问阴影半径的值。 I assumed I could do this:
我以为我可以这样做:
print(myImage.shadow.radius)
However, this returns an error: 但是,这会返回错误:
Value of type '(Color, Length, Length, Length) -> _ModifiedContent<_ModifiedContent, _ShadowEffect>' (aka '(Color, CGFloat, CGFloat, CGFloat) -> _ModifiedContent<_ModifiedContent, _ShadowEffect>') has no member 'radius'
类型'(颜色,长度,长度,长度) - > _ModifiedContent <_ModifiedContent,_ShadowEffect>'(又名'(Color,CGFloat,CGFloat,CGFloat) - > _ModifiedContent <_ModifiedContent,_ShadowEffect>')没有成员'radius'
Is there a way to access the modifier? 有没有办法访问修饰符?
The return type of myImage
is: myImage
的返回类型是:
_ModifiedContent<Image, _ShadowEffect>
We can access the original image by doing: 我们可以通过以下方式访问原始图像:
myImage.content
We can access the shadow effect modifier by typing: 我们可以通过输入以下命令来访问阴影效果修改器
myImage.modifier
So to do what you want, you have to type: 所以要做你想做的事,你必须输入:
print(myImage.modifier.radius)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.