Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
256 views
in Technique[技术] by (71.8m points)

swift - Random padding for rows using List in SwiftUI

In SwiftUi I have a list with dates.

There is padding to the left of each list item that I can't figure out how to correct....

See image

This is my body view

   var body: some View {
    VStack(alignment: .leading, spacing: 0){
    NavigationView {
      
        List{
            
             ForEach(calObject.dateArray,id: .self){date in
             
            DateRow(date: date)
            
             }
            
        }.navigationBarTitle("(calObject.nameOfMonth(calObject.stepper))")
            
    }
}

And this is my DateRow view

struct DateRow: View {
@ObservedObject private var calObject = CalendarObject()


var date: Date


var body: some View {
        HStack(){
      
        
            Text(calObject.rowDateFormatter(date).prefix(3)).bold()
                   .foregroundColor(.white)
                   .padding()
                   .background(Color.gray)
                   .mask(Circle())
                .padding(.trailing)
            
       
            Text("(calObject.rowDateFormatter(date))")
        
          Spacer()
          
    
        
        }
        
    }

Somebody who can help me with this really frustrating situation? =/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

remove .padding(.trailing) from text so all elements will have equal space

struct DateRow: View {
@ObservedObject private var calObject = CalendarObject()


var date: Date


var body: some View {
    HStack(){
  
    
        Text(calObject.rowDateFormatter(date).prefix(3)).bold()
               .foregroundColor(.white)
               .padding()
               .background(Color.gray)
               .mask(Circle())
               .frame(width: 45, height: 45)     
   
        Text("(calObject.rowDateFormatter(date))")
    
      Spacer()
      

    
    }
    
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...