Code Monkey home page Code Monkey logo

flagskit's Introduction

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.

flagskit's People

Contributors

pichukov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.