So i am trying to show a bunch to Texts in scrollView yet to bottom once not showing(they are in size of tableView line).
this is my code:
struct TestView: View {
@ObservedObject var viewModel: ViewModel
@State private var contentSize: CGSize = .zero
var body: some View {
ZStack {
ScrollView {
VStack {
Image(viewModel.image).resizable()
.scaledToFit()
.overlay(
Button(action: {
print(">> Trash Tapped")
//viewModel.dismiss
}) {
Image("closeBtn")
}.padding(.top, 30)
.padding(.trailing, 16),
alignment: .topTrailing
)
.padding(.bottom, 40)
Text(viewModel.firstText)
.padding(.trailing, 30)
.padding(.leading, 30)
.padding(.bottom, 40)
.multilineTextAlignment(.trailing)
.font(viewModel.firstFont)
.foregroundColor(viewModel.firstColor)
.lineLimit(nil)
Text(viewModel.secondText)
.padding(.trailing, 30)
.padding(.leading, 30)
.padding(.bottom, 5)
.multilineTextAlignment(.trailing)
.font(viewModel.secondFont)
.foregroundColor(viewModel.secondColor)
.lineLimit(nil)
Text(viewModel.thirdText)
.padding(.trailing, 30)
.padding(.leading, 30)
.padding(.bottom, 40)
.multilineTextAlignment(.trailing)
.font(viewModel.thirdFont)
.foregroundColor(viewModel.thirdColor)
.lineLimit(nil)
Text(viewModel.fourthText)
.padding(.trailing, 30)
.padding(.leading, 30)
.padding(.bottom, 5)
.multilineTextAlignment(.trailing)
.font(viewModel.fourthFont)
.foregroundColor(viewModel.fourthColor)
.lineLimit(nil)
Text(viewModel.fifthText)
.padding(.trailing, 30)
.padding(.leading, 30)
.padding(.bottom, 40)
.multilineTextAlignment(.trailing)
.font(viewModel.fifthFont)
.foregroundColor(viewModel.fifthColor)
.lineLimit(nil)
Text(viewModel.sixText)
.padding(.trailing, 22)
.padding(.leading, 22)
.padding(.bottom, 30)
.multilineTextAlignment(.trailing)
.font(viewModel.sixFont)
.foregroundColor(viewModel.sixColor)
.lineLimit(nil)
Text(viewModel.sixText)
.padding(.trailing, 22)
.padding(.leading, 22)
.padding(.bottom, 30)
.multilineTextAlignment(.trailing)
.font(viewModel.sixFont)
.foregroundColor(viewModel.sixColor)
.lineLimit(nil)
}
Spacer()
}
.edgesIgnoringSafeArea(.all)
}
.navigationBarHidden(true)
}
}
this is my vm:
final class ViewModel: ObservableObject, CryptoPopUpScreen {
var firstFont: Font
var firstColor: Color
var secondFont: Font
var secondColor: Color
var thirdFont: Font
var thirdColor: Color
var fourthFont: Font
var fourthColor: Color
var fifthFont: Font
var fifthColor: Color
var sixFont: Font
var sixColor: Color
var firstText: String
var secondText: String
var thirdText: String
var fourthText: String
var fifthText: String
var sixText: String
lazy var image = "cryptoPilot"
init() {
firstText = L10n.cryptoPilotTitle
firstColor = Color(ColorName.black)
firstFont = Font(UIFont(name: "Orion-Regular", size: 14)!)
secondText = L10n.cryptoPilotFirstTextTitle
secondColor = Color(ColorName.black)
secondFont = Font(UIFont(name: "Orion-Bold", size: 14)!)
thirdText = L10n.cryptoPilotFirstText
thirdColor = Color(ColorName.black)
thirdFont = Font(UIFont(name: "Orion-Regular", size: 14)!)
fourthText = L10n.cryptoPilotSecondTextTitle
fourthColor = Color(ColorName.black)
fourthFont = Font(UIFont(name: "Orion-Bold", size: 14)!)
fifthText = L10n.cryptoPilotSecondText
fifthColor = Color(ColorName.black)
fifthFont = Font(UIFont(name: "Orion-Regular", size: 14)!)
sixText = L10n.cryptoPilotInfo
sixColor = Color(ColorName.mushroom)
sixFont = Font(UIFont(name: "Orion-Regular", size: 1)!)
}
in the images we can see that the text is not with the height it suppose to be.
in a side project i mange to to it right. What am i missing?
CodePudding user response:
First of all, if you've got a lot of repeating modifiers, it would be worth it to create a custom modifier for yourself and use that, see reference https://www.hackingwithswift.com/books/ios-swiftui/custom-modifiers
secondly, for the sixFont you've set the size to 1, so I believe that would be your issue?
Lastly, since you're ignoring the safe insets on all edges, is it possible that they aren't shown because they are pushed out of the view? try not ignoring the bottom inset .