Skip to content

Commit

Permalink
add FontIcon.button
Browse files Browse the repository at this point in the history
  • Loading branch information
huybuidac committed Aug 29, 2020
1 parent b9a950d commit 6076c40
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 9 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Change log

## [2.1.0]
- Add static button function
```swift
FontIcon.button(.ionicon(code: .md_add_circle), action: {})
```

## [2.0.0]
- Make static text function:
```swift
FontIcon.text(.ionicon(code: .md_people), color: .white)
```

## [1.0.0]
- Create FontIcon core
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,27 @@ The easiest way to implement font icons in your SwiftUI project.

The library is super super easy to use, just something like this :)

### Text

```swift
import SwiftIconFont
...

// ...

FontIcon.text(.materialIcon(code: .access_alarm))
FontIcon.text(.materialIcon(code: .access_alarm), fontsize: 30)
```

There are 2 more options:
- color
- fontsize
![Test Image 3](/resources/demo_code.png)

### Button

```swift
FontIcon.text(.materialIcon(code: .access_alarm), fontsize: 30)
FontIcon.button(.ionicon(code: .md_add_circle), action: {})
FontIcon.button(.materialIcon(code: .settings), action: {}, padding: 8)
.background(RoundedRectangle(cornerRadius: 4).foregroundColor(.blue))
```

![Test Image 3](/resources/demo_code.png)

## Installation

### Cocoapods (Xcode 11 & Xcode 12)
Expand Down
13 changes: 13 additions & 0 deletions Sources/SwiftUIFontIcon/FontIconView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ public class FontIcon {

return color == nil ? text : text.foregroundColor(color!)
}

public static func button(_ fontCode: FontCode, action: @escaping () -> Void, padding: CGFloat = 0, fontsize: CGFloat = 20, color: Color? = nil) -> some View {
return button(fontCode, action: action, padding: .init(top: padding, leading: padding, bottom: padding, trailing: padding), fontsize: fontsize, color: color)
}

public static func button(_ fontCode: FontCode, action: @escaping () -> Void, padding: EdgeInsets, fontsize: CGFloat = 20, color: Color? = nil) -> some View {
Button(action: action) {
VStack{
text(fontCode, fontsize: fontsize, color: color)
}.padding(padding).contentShape(Rectangle())
}.buttonStyle(PlainButtonStyle())
}
}

struct ContentView_Previews: PreviewProvider {
Expand All @@ -39,6 +51,7 @@ struct ContentView_Previews: PreviewProvider {
.background(Color.red)
FontIcon.text(.materialIcon(code: .access_alarm), fontsize: 30)
.background(Color.red)
FontIcon.button(.materialIcon(code: .person), action: {})
}.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
}
}
3 changes: 3 additions & 0 deletions SwiftUIFontIcon.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SwiftUIFontIcon

struct ContentView: View {
var body: some View {
VStack {
VStack(alignment: .leading) {
HStack(alignment: .center){
Text("Material icon:").frame(width: 150, alignment: .trailing)
FontIcon.text(.materialIcon(code: .person))
Expand All @@ -29,6 +29,12 @@ struct ContentView: View {
.foregroundColor(.pink)
Spacer()
}.frame(height: 80)
HStack{
Text("Create button:").frame(width: 150, alignment: .trailing)
FontIcon.button(.ionicon(code: .md_add_circle), action: {})
FontIcon.button(.materialIcon(code: .settings), action: {}, padding: 8)
.background(RoundedRectangle(cornerRadius: 4).foregroundColor(.blue))
}.frame(height: 80)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SwiftUIFontIcon

struct ContentView: View {
var body: some View {
VStack {
VStack(alignment: .leading) {
HStack(alignment: .center){
Text("Material icon:").frame(width: 150, alignment: .trailing)
FontIcon.text(.materialIcon(code: .person))
Expand All @@ -29,6 +29,12 @@ struct ContentView: View {
.foregroundColor(.pink)
Spacer()
}.frame(height: 80)
HStack{
Text("Create button:").frame(width: 150, alignment: .trailing)
FontIcon.button(.ionicon(code: .md_add_circle), action: {})
FontIcon.button(.materialIcon(code: .settings), action: {}, padding: 8)
.background(RoundedRectangle(cornerRadius: 4).foregroundColor(.blue))
}.frame(height: 80)
}
}
}
Expand Down

0 comments on commit 6076c40

Please sign in to comment.