Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwiftUI #60

Merged
merged 4 commits into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add helper extension
Cleanup
  • Loading branch information
divadretlaw committed Feb 23, 2022
commit d1629803250d6c008c6cd44e9115b62873cccb5e
29 changes: 8 additions & 21 deletions Classes/SwiftUI/Awesome+Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
#if canImport(SwiftUI)
import SwiftUI

public extension Amazing {
@available(iOS 13, macOS 11, watchOS 6, tvOS 13, *)
var image: Awesome.Image<Self> {
Awesome.Image(icon: self)
}
}

extension Awesome {
@available(iOS 13, macOS 11, watchOS 6, tvOS 13, *)
/// A view wrapper around an Awesome.Icon
Expand Down Expand Up @@ -78,27 +85,7 @@ extension Awesome {
/// - Parameter color: The background color
public func backgroundColor(_ color: Amazing.Color) -> Self {
var view = self
view.backgroundColor = backgroundColor
return view
}

@available(iOS 14, macOS 11, watchOS 7, tvOS 14, *)
/// Changes the foreground color of the underlying image
///
/// - Parameter color: The color
public func foregroundColor(_ color: Color) -> Self {
var view = self
view.color = Amazing.Color(color)
return view
}

@available(iOS 14, macOS 11, watchOS 7, tvOS 14, *)
/// Changes the background color of the underlying image
///
/// - Parameter color: The background color
public func backgroundColor(_ color: Color) -> Self {
var view = self
view.backgroundColor = Amazing.Color(color)
view.backgroundColor = color
return view
}
}
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,26 @@ import Awesome
All icons are available through autogenerated enums like this:

```swift
// UKit and AppKit
let image = Awesome.Solid.handScissors.asImage(size: 40.0)
// or
let image = Awesome.Brand.android.asImage(size: CGSize(width: 40, height: 40), color: .red, backgroundColor: .blue) // :trollface:
// or
let attributedText = Awesome.Regular.envelopeOpen.asAttributedText(fontSize: 17, color: .red, backgroundColor: .blue)

// SwiftUI
Awesome.Brand.apple.image
// Set some modifiers
Awesome.Brand.android.image
.size(40)
.foregroundColor(.red)
.backgroundColor(.blue)
// Scales automatically with font
Awesome.Brand.android.image
.foregroundColor(.red)
.backgroundColor(.blue)
.font(.largeTitle)
// or
Awesome.Image(icon: Awesome.Brand.apple)
```

Expand Down