FlagsKit

main

pichukov/FlagsKit

FlagsKit is a swift package that contains more than 200 country flag png images. All the images are in low resulution (most of them are 250 x 125) what makes them together have a weight that less than 750 KB. Package provides a very simple way of getting a SwiftUI view with the flag you need. You can use it when you need a small image of the flag like in example below.

It also has mechanisms of converting Phone Code or Currency Code to Country code and getting Emoji flags based on Country, Phone or Currency code.

Installation

It's a Swift Package, so you need to do the following:

  • Open File in Xcode menu
  • Open Swift Packages
  • Choose Add Package Dependency... option
  • In the Enter package repository URL field paste this URL: https://github.com/pichukov/FlagsKit
  • Choose any existing version or take it from main branch

Usage

Add import FlagsKit to your swift file.

Country, Currency, Phone codes

By using Country enum you will be able to get a country code or Emoji flag of the country from Currency or Phone code. The following code example will print you CZ country code

let countryCode = Country.countryCode(fromPhoneCode: "+420")
print(countryCode)

If you need to get a country code from Currency code, you can do it like this:

let countryCode = Country.countryCode(fromCurrencyCode: "USD")
print(countryCode)

In that case US will be prented

Emoji flags

To get an Emoji flag you can use one of the followint methods:

Country.flagEmoji(forCountryCode: "US")     // -> πŸ‡ΊπŸ‡Έ
Country.flagEmoji(forCurrencyCode: "USD")   // -> πŸ‡ΊπŸ‡Έ
Country.flagEmoji(forPhoneCode: "+420")     // -> πŸ‡¨πŸ‡Ώ

FlagView

If you need a SwiftUI view with country flag, use the following code:

FlagView(countryCode: "US")

If you need a circle flag or the one with rounded corners, use style parameter:

 FlagView(countryCode: "ro", style: .circle)
    .frame(width: 50, height: 50)

In this example you will have a circle 50 by 50 flag.

Description

  • Swift Tools 5.7.0
View More Packages from this Author

Dependencies

  • None
Last updated: Fri Mar 15 2024 22:48:29 GMT-0900 (Hawaii-Aleutian Daylight Time)