swift - SwiftUI Button 文本对齐问题
问题描述
我想在这样的手表应用中制作 UI
但是信息按钮文本对齐不正确。见下图:尝试使用文本“i”和系统图像“信息”,仍然是同样的问题
这是我的代码:
VStack {
TextField("User Name", text: $userName)
.textContentType(.username)
.multilineTextAlignment(.center)
SecureField("Password", text: $password)
.textContentType(.password)
.multilineTextAlignment(.center)
Spacer()
Spacer()
HStack {
Button(action: {
//action
}) {
Text("Go")
}.disabled(userName.isEmpty || password.isEmpty)
.frame(width: 80, height: 40, alignment: Alignment.bottom)
Spacer()
VStack {
Spacer()
Button(action: {
//action
}) {
Image(systemName: "info")
}.frame(width: 25, height: 25, alignment: Alignment.bottom)
.foregroundColor(.black)
.background(Color.white)
.clipShape(Circle())
}
}
}
解决方案
您只是不需要那些框架对齐和间隔,通过删除那些让默认中心对齐生效:
HStack(alignment: .bottom) { // << here !!
Button(action: {
//action
}) {
Text("Go")
}.disabled(userName.isEmpty || password.isEmpty)
.frame(width: 80, height: 40)
Spacer()
Button(action: {
//action
}) {
Image(systemName: "info")
}.frame(width: 25, height: 25)
.foregroundColor(.black)
.background(Color.white)
.clipShape(Circle())
}
推荐阅读
- asp.net-core - 为什么我的 ASP.NET Core 数据库无法在我的 Raspberry Pi 3 上的 Windows IoT 中运行?
- java - 有没有办法通过使用 FirestoreRecyclerAdapter 组合查询游标来对查询进行分页?
- jquery - 使用ajax调用在移动设备上滚动页面时防止touchstart
- python - 如何在不添加列和索引名称的情况下旋转数据框
- java - 即使资源不应该存在也得到响应
- php - 为什么我不能在 prestashop 1.7 的主题中嵌入我的模板?
- javascript - 电子邮件正则表达式返回空
- mysql - 在 GROUP BY 中选择 MAX,但在 MYSQL 中将结果限制为 1
- django - 找到默认的 ROUTING 键 - 在通道 2 中不再需要此键
- c# - 如何在 Windows 窗体中立即启动计时器?