I have a functionality where the user can swipe through months using buttons:
@State private var selectedDate: Date = Date.now
ToolbarItem(placement: .principal) {
HStack {
Button {
//removing one month to the date
selectedDate = Calendar.current.date(byAdding: .month, value: -1, to: selectedDate) ?? selectedDate
} label: {
Image(systemName: "chevron.left.circle.fill")
}
Text(("(selectedDate, format: .dateTime.month())"))
.fontWeight(.bold)
.font(. system(size: 18))
Button {
//adding one month to the date
selectedDate = Calendar.current.date(byAdding: .month, value: 1, to: selectedDate) ?? selectedDate
} label: {
Image(systemName: "chevron.right.circle.fill")
}
//this is working but its still allowing the user to click into the next month
.disabled(selectedDate > Date.now)
I want to disable the right chevron so the user can’t click on the next month if its in the future but my current implementation still allows the user to go one month into the future before disabling the button, I need the right chevron button disabled if the user is in the current month.
}
}