Giter VIP home page Giter VIP logo

materialcolors-swift's Introduction

MaterialColors

MaterialColors is a swift package for quickly implementing colors from Material Design in your applications. It supports UIKit, AppKit, and SwiftUI, as well as platform light and dark user interface styles

Setup

MaterialColors uses the The Swift Package Manager for distrubition. For now, this is the only supported method of installation, but others will be added soon.

Add MaterialColors to your Package.swift file like so:

dependencies: [
    .package(url: "https://github.com/vsanthanam/MaterialColors-Swift.git", .upToNextMajor(from: "0.0.0"))
]

Usage

UIKit

import MaterialColors
import UIKit

let view = UIView()
view.backgroundColor = .material(.red400)
import MaterialColors
import UIKit

let dynamicView = UIView()
view.backgroundColor = .material(light: .grey50, dark: .grey400)

AppKit

import AppKit
import MaterialColors

let view = NSView()
view.backgroundColor = .material(.green50)

CoreGraphics

import CoreGraphics
import MaterialColors
import UIKit

let view = UIView()
view.layer.background = .material(.purple300)
import AppKit
import CoreGraphics
import MaterialColors

let view = NSView()
view.layer.background = .material(.orange200)

SwiftUI

import MaterialColors
import SwiftUI

struct MyView: View {

    var body: some View {
        Rectangle()
            .foregroundColor(.material(.deepPurple400))
    }

}

Strings

You can also create material colors from strings and string literals. This can be useful if you are parsing some value from an http response:

import MaterialColors
import UIKit

let uicolor: UIColor = .material("red400")

let string = "red400"
let color = MaterialColor(string)

let nscolor: NSColor = .material(color)

Converting Backwards

You can also determine whether a given color is one of the standard material design colors, and if so, which one it is:

import MaterialColors
import UIKit
import XCTest

let materialColor: UIColor = .material(.red400)
let nonMaterialColor = UIColor.blue

XCTAssertNil(nonMaterialColor.asMaterialColor)
XCTAssertEqual(materialColor.asMaterialColor, .red400)

materialcolors-swift's People

Contributors

vsanthanam avatar

Stargazers

 avatar

Watchers

 avatar  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.