0

在使用 SwiftUI 时,我在将我的“twitter”图像放在我的视图中时遇到问题。我想让 twitter 图像更接近我的两个 blob 图像,并在 twitter 图像和“登录我的帐户”短语之间添加间距。此外,我正在尝试获取我的 UITextfield,我想现在它只是 TextField 在我的“登录您的帐户短语”下方单击时出现在键盘上,但这现在显示在我的视图中。

请参阅附件中发生的事情的图片。推特远离斑点

    GeometryReader { (deviceSize: GeometryProxy) in

        ZStack {
            //Define a screen color
            LinearGradient (gradient: Gradient(colors:[Color(ColorsSaved.gitLabDark),Color(ColorsSaved.gitLabLight)]),startPoint: .leading,endPoint: .trailing)

                //Extend the screen to all edges
                .edgesIgnoringSafeArea(.all)
            Image("blobVectorLight")
                .resizable()
                .frame(width: deviceSize.size.height * (220/812) * 0.81, height: deviceSize.size.height * (220/812), alignment: .topTrailing)
                .frame(width: deviceSize.size.width, height:deviceSize.size.height , alignment: .topTrailing)
                .edgesIgnoringSafeArea(.all)

            Image("blobVectorDark")
                .resizable()
                .frame(width: deviceSize.size.height * (208/812) * 0.74, height: deviceSize.size.height * (208/812), alignment: .topTrailing)
                // .overlay(Image("blobVectorLight"))
                .frame(width: deviceSize.size.width, height:deviceSize.size.height , alignment: .topTrailing)
                .edgesIgnoringSafeArea(.all)

            VStack{

                Image ("twitter")
                    .resizable()
                    .frame(width: deviceSize.size.height*(77/812)*2.078, height: deviceSize.size.height*(77/812))

                Text ("Sign into your account")
                    .foregroundColor(.white)

                TextField ("Username")

            }
        }
    }
}

}
4

2 回答 2

1

我只是总结了你应该在这里做的所有事情:

           VStack(spacing: 50){

            Spacer()
            Image ("image")
                .resizable()
                .frame(width: deviceSize.size.height*(77/812)*2.078, height: deviceSize.size.height*(77/812))
            Spacer()
            Text ("Sign into your account")
                .foregroundColor(.white)

            TextField.init("Username", text: self.$userName)
            Spacer()
        }

身体上方:

   @State var userName: String = ""
   var body: some View {
  ......

希望你得到你想要的。

于 2019-11-26T18:19:42.590 回答
1

要向上移动任何元素,请使用:

.offset(y: -200.0)

要增加 VStack 中元素之间的间距,请像这样声明它:

VStack(spacing: 20.0) { //....

太使用 TextField 您需要一个值将其绑定到:

//outside the body declare:
@State private var username: String = ""

//and then inside the body:
TextField("Username", text: $username)
于 2019-11-26T07:58:29.020 回答