Here is a visual of my Swift project so far.
I want to have a consistent padding around each description. As you can see, that is not being achieved, even though I applied a consistent padding constant. I think the problem has to do with each text block and their different spacings. I.E the second one has a space right after "hairs" but ends before the space, perhaps adding the space to the .leading padding somehow. Also note that the .leading padding for the images are shifted correspondingly.
Because the text in these blocks will eventually come from user input (not the random text I have here) it is critical that consistent padding is applied with any combination of text and spaces.
What is going wrong here?
Current code:
struct Header: View {
var name: String
var connection: String
var image: String
init(name: String, connection: String, image: String) {
self.name = name
self.connection = connection
self.image = image
}
var body: some View {
HStack() {
Image(self.image)
.resizable()
.frame(width: 60, height: 60)
.clipShape(Circle())
VStack(alignment: .leading) {
Text(self.name)
.font(.headline)
.fontWeight(.semibold)
.foregroundColor(Color.black)
.frame(alignment: .leading)
Text(self.connection)
.font(.callout)
.fontWeight(.medium)
.foregroundColor(Color.gray)
.frame(alignment: .leading)
}
}
}
}
struct Description: View {
var description: String
init(description: String) {
self.description = description
}
var body: some View {
Text(self.description)
.multilineTextAlignment(.leading)
}
}
struct Post: View {
var data: PostData
init(data: PostData) {
self.data = data
}
var body: some View {
HStack(alignment: .top) {
Spacer()
.frame(width: 110)
VStack(alignment: .leading, spacing: 0.0) {
Header(name: self.data.name, connection: self.data.connection, image: self.data.image)
.padding(.top, 10)
.padding(.bottom, 6)
.padding(.leading, 6)
Description(description: self.data.description)
.padding(.bottom, 6)
.padding(.leading, 7)
.padding(.trailing, 5)
}
.frame(maxWidth: .infinity)
.border(Color.black)
}
}
}
struct PostView: View {
var body: some View {
VStack(spacing: -1.0) {
Spacer()
Post(data: one)
Post(data: two)
Post(data: three)
}
}
}
