SwiftUI GeometryReader does not layout custom subviews in center

后端 未结 3 446
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-17 18:59

I have a custom view:

struct ImageContent: View {
    var body: some View {
        Image(\"smile\")
            .resizable()
            .scaledToFit()
             


        
3条回答
  •  旧巷少年郎
    2021-01-17 19:37

    Try the following (built-in container by default expanded to size of GeometryReader and have explicit default alignment set to center by both dimensions). Tested with Xcode 11.2.

    var body: some View {
        GeometryReader { geometry in
           VStack { // explicit container with center default alignment
            ImageContent()
           }
        }
    }
    

提交回复
热议问题