垂直对齐图像在TextEditor中

huangapple go评论64阅读模式
英文:

Vertically align Image within TextEditor

问题

I am attempting to have my image and textEditor text to both be centered vertically within the TextEditor (similar to the textField below it. I tried GeometryReader to no avail, along with any alignment trick I could think of.

Any help would be great!

HStack {
Image(systemName: "person.crop.rectangle")
.foregroundColor(Color("ButtonTwo"))

TextEditor(text: $userBio)
    .foregroundColor(.gray)
    .padding(.leading, 20)

}

垂直对齐图像在TextEditor中

英文:

I am attempting to have my image and textEditor text to both be centered vertically within the TextEditor (similar to the textField below it. I tried GeometryReader to no avail, along with any alignment trick I could think of.

Any help would be great!

HStack {
                Image(systemName: "person.crop.rectangle")
                    .foregroundColor(Color("ButtonTwo"))
                   
                TextEditor(text: $userBio)
                    .foregroundColor(.gray)
                    .padding(.leading, 20)
            }

垂直对齐图像在TextEditor中

答案1

得分: 1

希望这能给你一些想法。

HStack(spacing: 20) {
    Image(systemName: "person.crop.rectangle")
        .foregroundColor(.mint)
               
    TextEditor(text: $text)
        .foregroundColor(.gray)
        .frame(minHeight: 44)
        .fixedSize(horizontal: false, vertical: true)
}
.padding()
.border(Color.gray, width: 1)

当在文本编辑器中有多行文本时,会得到以下结果:

垂直对齐图像在TextEditor中

英文:

hope this will give you some ideas

HStack(spacing: 20) {
    Image(systemName: "person.crop.rectangle")
        .foregroundColor(.mint)
               
    TextEditor(text: $text)
        .foregroundColor(.gray)
        .frame(minHeight: 44)
        .fixedSize(horizontal: false, vertical: true)
}
.padding()
.border(Color.gray, width: 1)

this is what you get when having multiple lines in your text editor
垂直对齐图像在TextEditor中

huangapple
  • 本文由 发表于 2023年3月23日 12:20:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/75819220.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定