Here's a SwiftUI view that creates an airport departure board:
import SwiftUI
struct DepartureBoardView: View {
@State private var flights = [
Flight(flightNumber: "AA1234", destination: "New York", gate: "A12", time: "14:30", status: .onTime),
Flight(flightNumber: "DL5678", destination: "Los Angeles", gate: "B7", time: "15:15", status: .delayed),
Flight(flightNumber: "UA9012", destination: "Chicago", gate: "C3", time: "16:45", status: .boarding),
Flight(flightNumber: "SW3456", destination: "Denver", gate: "A8", time: "17:20", status: .onTime),
Flight(flightNumber: "JB7890", destination: "Boston", gate: "B15", time: "18:00", status: .cancelled)
]
var body: some View {
VStack(spacing: 0) {
// Header
HStack {
Text("DEPARTURES")
.font(.largeTitle)
.fontWeight(.bold)
.foregroundColor(.white)
Spacer()
Text(currentTime)
.font(.title2)
.foregroundColor(.white)
}
.padding()
.background(Color.black)
// Column Headers
HStack {
Text("FLIGHT")
.frame(width: 80, alignment: .leading)
Text("DESTINATION")
.frame(maxWidth: .infinity, alignment: .leading)
Text("GATE")
.frame(width: 60, alignment: .center)
Text("TIME")
.frame(width: 80, alignment: .center)
Text("STATUS")
.frame(width: 100, alignment: .center)
}
.font(.caption)
.fontWeight(.semibold)
.foregroundColor(.gray)
.padding(.horizontal)
.padding(.vertical, 8)
.background(Color.gray.opacity(0.1))
// Flight List
ScrollView {
LazyVStack(spacing: 1) {
ForEach(flights) { flight in
FlightRowView(flight: flight)
}
}
}
}
.background(Color.black)
}
private var currentTime: String {
let formatter = DateFormatter()
formatter.timeStyle = .short
return formatter.string(from: Date())
}
}
struct FlightRowView: View {
let flight: Flight
var body: some View {
HStack {
Text(flight.flightNumber)
.font(.system(.body, design: .monospaced))
.fontWeight(.medium)
.frame(width: 80, alignment: .leading)
Text(flight.destination)
.font(.body)
.frame(maxWidth: .infinity, alignment: .leading)
Text(flight.gate)
.font(.system(.body, design: .monospaced))
.fontWeight(.medium)
.frame(width: 60, alignment: .center)
Text(flight.time)
.font(.system(.body, design: .monospaced))
.frame(width: 80, alignment: .center)
Text(flight.status.displayText)
.font(.caption)
.fontWeight(.semibold)
.foregroundColor(flight.status.color)
.frame(width: 100, alignment: .center)
.padding(.vertical, 4)
.padding(.horizontal, 8)
.background(flight.status.color.opacity(0.2))
.cornerRadius(4)
}
.padding(.horizontal)
.padding(.vertical, 12)
.background(Color.white)
.foregroundColor(.black)
}
}
struct Flight: Identifiable {
let id = UUID()
let flightNumber: String
let destination: String
let gate: String
let time: String
let status: FlightStatus
}
enum FlightStatus {
case onTime
case delayed
case boarding
case cancelled
case departed
var displayText: String {
switch self {
case .onTime: return "ON TIME"
case .delayed: return "DELAYED"
case .boarding: return "BOARDING"
case .cancelled: return "CANCELLED"
case .departed: return "DEPARTED"
}
}
var color: Color {
switch self {
case .onTime: return .green
case .delayed: return .orange
case .boarding: return .blue
case .cancelled: return .red
case .departed: return .gray
}
}
}
#Preview {
DepartureBoardView()
}
This departure board includes:
Key Features:
- Clean, airport-style layout with monospaced fonts for flight numbers and times
- Color-coded status indicators (green for on-time, orange for delayed, etc.)
- Scrollable list of flights
- Real-time clock display in the header
- Proper column alignment mimicking real departure boards
Customization Options:
- Add a timer to refresh flight data periodically
- Include airline logos or icons
- Add animations for status changes
- Implement pull-to-refresh functionality
- Add filtering options (by airline, destination, etc.)
The view uses a dark header with white text to match typical airport displays, and each flight row has clear visual separation with appropriate spacing and typography.