I'm using SwiftUI to develop a people list page, the iPhone X screen is big enough but the titles are out of the screen in iPhone 8:
iPhone X:
However in iPhone 8 or smaller screen the "Find People" is too close to left and "Follow All" is even out of screen:
I know in UIKit autolayout will solve this very easy but I wonder what's the best way or proper way for SwiftUI to solve this, some answer saying using like Spacer
or HStack
, but none of them actually work.
var body: some View {
NavigationView {
List {
ForEach(people) {person in
PersonView(person: person)
}
}.navigationBarItems(leading:
VStack(spacing: 10) {
HStack(spacing: 100) {
Text("Find People").font(.system(size: 30)).bold()
Text("Follow All").foregroundColor(Color(ColorUtils.hexStringToUIColor(hex: Constants.THEME.THEME_COLOR)))
}
HStack(spacing: 20) {
Text("Import from: ")
ForEach(socialIcons, id: \.self) {icon in
Image(icon).resizable().frame(width: 25, height: 25)
}
}
}
)
}
}
You are putting static spacing so that issue is occurring. you can fix it using Spacer()
Modifier and give some Frame()
.
var body: some View {
NavigationView {
List {
ForEach(peoples, id: \.self) {person in
PersonView(person: person)
}
}.navigationBarItems(leading:
VStack(spacing: 5) { // Change Spacing as you want
HStack {
Text("Find People").font(.system(size: 30)).bold()
Spacer()
Text("Follow All").foregroundColor(Color(ColorUtils.hexStringToUIColor(hex: Constants.THEME.THEME_COLOR)))
}
HStack() {
Text("Import from:")
Spacer()
ForEach(socialIcons, id: \.self) {icon in
Image(icon).resizable().frame(width: 25, height: 25)
.padding(.horizontal)
}
}
}.frame(width: UIScreen.main.bounds.width-20, alignment: .center)
)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With