Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vsanthanam/MaterialColors-Swift
A swift package for implementing colors from Material Design
https://github.com/vsanthanam/MaterialColors-Swift
appkit cgcolor ios macos material-design nscolor nsview spm swift swift-library swiftui tvos uicolor uikit uiview watchos xcode
Last synced: 3 months ago
JSON representation
A swift package for implementing colors from Material Design
- Host: GitHub
- URL: https://github.com/vsanthanam/MaterialColors-Swift
- Owner: vsanthanam
- License: mit
- Created: 2021-07-02T20:31:30.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-10-12T17:20:25.000Z (over 3 years ago)
- Last Synced: 2023-08-19T19:47:44.486Z (over 1 year ago)
- Topics: appkit, cgcolor, ios, macos, material-design, nscolor, nsview, spm, swift, swift-library, swiftui, tvos, uicolor, uikit, uiview, watchos, xcode
- Language: Swift
- Homepage: https://swiftmaterialcolors.dev
- Size: 1.35 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MaterialColors
MaterialColors is a swift package for quickly implementing colors from [Material Design](https://www.material.io) 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](https://swift.org/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:
```swift
dependencies: [
.package(url: "https://github.com/vsanthanam/MaterialColors-Swift.git", .upToNextMajor(from: "0.0.0"))
]
```## Usage
### UIKit
```swift
import MaterialColors
import UIKitlet view = UIView()
view.backgroundColor = .material(.red400)
```
```swift
import MaterialColors
import UIKitlet dynamicView = UIView()
view.backgroundColor = .material(light: .grey50, dark: .grey400)
```### AppKit
```swift
import AppKit
import MaterialColorslet view = NSView()
view.backgroundColor = .material(.green50)
```### CoreGraphics
```swift
import CoreGraphics
import MaterialColors
import UIKitlet view = UIView()
view.layer.background = .material(.purple300)
```
```swift
import AppKit
import CoreGraphics
import MaterialColorslet view = NSView()
view.layer.background = .material(.orange200)
```### SwiftUI
```swift
import MaterialColors
import SwiftUIstruct 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:
```swift
import MaterialColors
import UIKitlet 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:
```swift
import MaterialColors
import UIKit
import XCTestlet materialColor: UIColor = .material(.red400)
let nonMaterialColor = UIColor.blueXCTAssertNil(nonMaterialColor.asMaterialColor)
XCTAssertEqual(materialColor.asMaterialColor, .red400)
```