Skip to content

johannes-bln/TransportSymbols

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TransportSymbols

Swift Platform License SwiftPM Build

First of all: I wrote this library a long time ago for the simple reason that it is reusable. I found it too time-consuming to keep rewriting it for different apps, so now you can always import it, which makes things a lot faster.

A lightweight SwiftUI library that provides consistent, scalable transport line symbols for iOS, macOS, watchOS, and Mac Catalyst.
Designed for apps that display public transport data such as S-Bahn, U-Bahn, Tram, Bus, Ferry, or regional trains.


Examples

1. Standart Icon

In this example, we display a simple transport symbol, without any further customization. The example demonstrates how easy it is to use, simply by importing the TransportSymbols.

import SwiftUI
import TransportSymbols

struct ContentView: View {
    var body: some View {
        VStack {
            SbahnSymbolView() 
        }
    }
}

1. Preview

It's very simple; with just a few lines of code, you can add the symbol. SimplePReview

2. Usage in station list

In this example, we show how to display the symbols in a simple list with sample station names, simply by importing the TransportSymbols.

import SwiftUI
import TransportSymbols

struct ContentView: View {
    var body: some View {
        List {
            stationRow(name: "Example", sbahn: true, ubahn: true, tram: true)
            stationRow(name: "Test", sbahn: false, ubahn: true, tram: true)
            stationRow(name: "Some Place", sbahn: false, ubahn: true, tram: false)
        }
    }
    
    @ViewBuilder
    func stationRow(name: String, sbahn: Bool, ubahn: Bool, tram: Bool) -> some View {
        VStack(alignment: .leading, spacing: 3) {
            Text(name)
                .bold()
            
            HStack {
                if sbahn { SbahnSymbolView() }
                if ubahn { UbahnSymbolView() }
                if tram { TramSymbolView() }
            }
        }
    }
}

#Preview {
    ContentView()
}

2. Preview

A bit broken down, but that's how you could do it. ExampleInList

3. Custom Symbol/Text

You can also create your own symbols based on this pattern.

import SwiftUI
import TransportSymbols

struct ContentView: View {
    var body: some View {
        VStack {
            TransportSymbolView(backgroundColor: .green) {
                Image(systemName: "tram")
                    .imageScale(.small)
                    .foregroundStyle(.white)
                    
            }
        }
    }
}
#Preview {
    ContentView()
}

3. Preview

Here is an example with an SF symbol. ExampleWithSymbol

About

TransportSymbols is a small collection of SwiftUI components for compact, system-oriented transport symbols (suburban train, subway, tram, bus, ferry, regional, long-distance, on foot). Each symbol is designed as a rounded badge, scales cleanly in compact layouts, and can be easily customized as needed.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages