【发布时间】:2020-08-18 18:34:44
【问题描述】:
我试图在我的应用程序上使用某种类型的提交表单,但由于某种原因我无法放置 UItextfields。我在这个结构的开头声明了它们,但是在显示时我得到了错误:
“类型'()'不能符合'View';只有结构/枚举/类类型可以符合协议”
import SwiftUI
import UIKit
/// Shows a list of inspiring quotes/bio
struct FeatureView: View {
@State private var userEmail: UITextField = UITextField(frame: CGRect(x:10, y:320, width:300.00, height:30.00))
private var instagramName: UITextField = UITextField(frame: CGRect(x:10, y:320, width:300.00, height:30.00))
var body: some View {
VStack {
HStack {
VStack(alignment: .leading) {
Text("Get Featured").font(.largeTitle).bold()
Spacer()
Text("1. Submit your information below")
Spacer()
Text("2. On the 1st and 14th we choose a new account to feature")
Spacer()
Text("3. Get notified by e-mail if your account is chosen!")
Spacer()
}
Spacer()
userEmail.placeholder = "email"
userEmail.addSubview(userEmail)
}.padding(EdgeInsets(top: 20, leading: 20, bottom: 0, trailing: 20))
}
}
}
我现在只是想显示和编辑一个电子邮件字段,但最终我想要 5-6 个不同的字段,它们都包含我最终可以让用户提交的信息
【问题讨论】:
-
使用 SwiftUI
TextField而不是尝试混合两种不同的界面风格怎么样? -
只是一个小提示:您不需要导入 SwiftUI 和 UIKit,因为 SwiftUI 已经包含 UIKit...
标签: ios swift xcode uitextview