Skip to content

๐ŸŽ A collection of all country flags to be used in Swift

License

Notifications You must be signed in to change notification settings

malczak/flag-icon-swift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

12 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

flag-icon-swift

๐ŸŽ A collection of all country flags to be used in iOS apps

A collection of all country flags in PNG โ€” plus the sprite sheet for iOS apps and Swift class for accessing country flags by country code (ISO 3166-1 alpha-2)

Usage

Simple use case

    if let flagSheet = FlagIcons.loadDefault() {
        let image = flagSheet.getImageFor("PL")
        // ...
    }

In the example above created image is reusing a memory already allocated to store flags sheet. Image is valid as long as flagSheet exists. Underlying UIImage is cached and shared between calls, cache can be flushed with flagSheet?.flushCache() call.

Use deepCopy parameter to create copy of a flag image. Underlying bytes will be copied over to new image data

    if let flagSheet = FlagIcons.loadDefault() {
        let image = flagSheet.getImageFor("PL", deepCopy: true)
        // ...
    }

Additionaly its possible to get country names

    if let countries = FlagIcons.loadCountries() {
        if let country = countries.first(where: { $0.code == "PL" }) {
            print(country.name) // output: Poland
        }
    }

Production use

This repo is used in one of my apps - Last Day? Life progress and stats

Sample application

For usage example please see sample country flags application


> cd FlagIconSample
> pod install

Sample Flags App

Credits

This project wouldn't exist without the awesome flag-ison-css


About

๐ŸŽ A collection of all country flags to be used in Swift

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published