SwiftUI:如何将图标对齐到居中文本字段的左侧?
我在 SwiftUI 中有一个位于屏幕中央的 TextField。我想立即添加一个铅笔图标。它的左侧表明它是可编辑的 - 我该如何做到这一点?我尝试将 TextField 和 Image 嵌入到 HStack 中,如下所示:
HStack {
Spacer()
Image(systemName: "pencil")
TextField(...)
}
但这只会产生类似这样的结果: 其中文本字段不再居中,并且铅笔与屏幕左侧对齐。
任何指导表示赞赏。
I've got a TextField in SwiftUI that is centered on the screen. I want to add a pencil icon immediately. to the left of it to indicate that it is editable - how can I do this? I've tried embedding both the TextField and Image in an HStack like this:
HStack {
Spacer()
Image(systemName: "pencil")
TextField(...)
}
But that only yields something like this:
where the textfield is no longer centered and the pencil is aligned to the left of the screen.
Any guidance is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该可以做到:
this should do it: