Skip to content

Commit 2e63080

Browse files
Update README.md
1 parent c00eeaa commit 2e63080

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

README.md

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,20 @@ import ExpandableButton
2121
```
2222

2323
## Usage
24-
With `image` and `action`:
24+
You can init **ExpandableButton** with `frame` (default is `.zero`), `direction` (default is `.right`) and items (each item will be button). `direction` is opening direction. `items` is `[ExpandableButtonItem]` whiches contain information about future buttons.
25+
Diretions example:
26+
``` swift
27+
let rightButton = ExpandableButtonView(frame: frame, direction: .right, items: items)
28+
let leftButton = ExpandableButtonView(frame: frame, direction: .left, items: items)
29+
let upButton = ExpandableButtonView(frame: frame, direction: .up, items: items)
30+
let downButton = ExpandableButtonView(frame: frame, direction: .down, items: items)
31+
```
32+
![](Contents/right.gif)
33+
![](Contents/left.gif)
34+
![](Contents/up.gif)
35+
![](Contents/down.gif)
36+
37+
Items with `image` and `action`:
2538
``` swift
2639
// create items with images and actions
2740
let items = [
@@ -61,7 +74,7 @@ let insets = UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 16)
6174
let items = [
6275
ExpandableButtonItem(
6376
image: UIImage(named: "delete"),
64-
highlightedImage: UIImage(named: "delete")!.alpha(0.5),
77+
highlightedImage: UIImage(named: "highlightedDelete"),
6578
imageEdgeInsets: insets,
6679
action: {_ in
6780
print("delete")
@@ -89,9 +102,9 @@ buttonView.closeOpenImagesInsets = insets
89102
```
90103
![](Contents/example4.gif)
91104

92-
With `attributedTitle`, `highlightedAttributedTitle` and custom item `width`:
105+
With `attributedTitle`, `highlightedAttributedTitle` and custom item `size`:
93106
``` swift
94-
// with attributed string, highlighted attributed string, custom width.
107+
// with attributed string, highlighted attributed string, custom size.
95108
let items = [
96109
ExpandableButtonItem(
97110
attributedTitle: NSAttributedString(
@@ -102,13 +115,13 @@ let items = [
102115
string: "Attributed Text",
103116
attributes: [.foregroundColor: UIColor.green]
104117
),
105-
width: 160
118+
size: CGSize(width: 160, height: 60)
106119
)
107120
]
108121
```
109122
![](Contents/example5.gif)
110123

111-
With `attributedTitle` under `image` (using `contentEdgeInsets`, `titleEdgeInsets`, `imageEdgeInsets`, `titleAlignment`, `imageContentMode`):
124+
With `attributedTitle` under `image` (using `contentEdgeInsets`, `titleEdgeInsets`, `imageEdgeInsets`, `titleAlignment`, `imageContentMode`, `size`):
112125
``` swift
113126
let attributedTitle = NSAttributedString(
114127
string: "Share",
@@ -124,13 +137,14 @@ let highlightedAttributedTitle = NSAttributedString(
124137

125138
let items = [
126139
ExpandableButtonItem(
127-
image: #imageLiteral(resourceName: "share"),
128-
highlightedImage: #imageLiteral(resourceName: "share").alpha(0.5),
140+
image: UIImage(named: "share"),
141+
highlightedImage: UIImage(named: "haglightedShare"),
129142
attributedTitle: attributedTitle,
130143
highlightedAttributedTitle: highlightedAttributedTitle,
131144
contentEdgeInsets: UIEdgeInsets(top: 6, left: 6, bottom: 6, right: 6),
132145
titleEdgeInsets: UIEdgeInsets(top: 24, left: -200, bottom: 0, right: 0),
133146
imageEdgeInsets: UIEdgeInsets(top: 6, left: 0, bottom: 24, right: 0),
147+
size: CGSize(width: 80, height: 60),
134148
titleAlignment: .center,
135149
imageContentMode: .scaleAspectFit
136150
)
@@ -150,20 +164,20 @@ buttonView.close()
150164
### [`ExpandableButtonView`](ExpandableButton/ExpandableButtonView.swift)
151165
| Name | Type | Default value | Description |
152166
| :--- | :--- | :--- | :--- |
167+
| `direction` | `Direction` | `.right` | Opening direction. Could be `.left`, `.right`, `.up`, `.down`. Set only on `init(frame:direction:items:)`.
153168
| `state` | `State` | `.closed` | Current state. Could be `.opened`, `.closed` or `.animating`. |
154169
| `animationDuration` | `TimeInterval` | `0.2` | Opening, closing and arrow animation duration. |
155170
| `closeOnAction` | `Bool` | `false` | If `true` call `close()` after any item action. |
156171
| `isHapticFeedback` | `Bool` | `true` | Turn on haptic feedback (Taptic engine) |
157-
| `arrowInsets` | `UIEdgeInsets` | `top: 8, left: 12, bottom: 8, right: 12` | Arrow insets. |
172+
| `arrowInsets` | `UIEdgeInsets` | `top: 12 left: 12 bottom: 12 right: 12` | Arrow insets. |
158173
| `arrowWidth` | `CGFloat` | `1` | Arrow line width. |
159174
| `arrowColor` | `UIColor` | `UIColor.black` | Arrow color. |
160175
| `closeOpenImagesInsets` | `UIEdgeInsets` | `.zero` | Insets for custom close and open images. |
161176
| `closeImage` | `UIImage?` | `nil` | Custom close image. |
162177
| `openImage` | `UIImage?` | `nil` | Custom open image. |
163178
| `isSeparatorHidden` | `Bool` | `false` | If `true` hide separator view. |
164179
| `separatorColor` | `UIColor` | `UIColor.black` | Separator color. |
165-
| `separatorTopOffset` | `CGFloat` | `8` | Separator view top offset. |
166-
| `separatorBottomOffset` | `CGFloat` | `8` | Separator view bottom offset. |
180+
| `separatorInset` | `CGFloat` | `8` | Separator inset from top, bottom for `.left`, `.right` directions and from left, right for `up`, `down`. |
167181
| `separatorWidth` | `CGFloat` | `1` | Separator view width. |
168182

169183
### [`ExpandableButtonItem`](ExpandableButton/ExpandableButtonItem.swift)
@@ -176,14 +190,14 @@ buttonView.close()
176190
| `contentEdgeInsets` | `UIEdgeInsets` | `.zero` | `contentEdgeInsets` for `UIButton` |
177191
| `titleEdgeInsets` | `UIEdgeInsets` | `.zero` | `titleEdgeInsets` for `UIButton`. |
178192
| `imageEdgeInsets` | `UIEdgeInsets` | `.zero` | `imageEdgeInsets` for `UIButton`. |
179-
| `width` | `CGFloat?` | `nil` | `UIButton` width for current item. If `nil` will be equal to arrow button width. |
193+
| `size` | `CGSize?` | `nil` | `UIButton` size for current item. If `nil` will be equal to arrow button size. |
180194
| `titleAlignment` | `NSTextAlignment` | `.center` | `titleAlignment` for `titleLabel` in `UIButton`. |
181195
| `imageContentMode` | `UIViewContentMode` | `.scaleAspectFit` | `imageContentMode` for `imageView` in `UIButton`.|
182196
| `action` | `(ExpandableButtonItem) -> Void` | `{_ in}` | Action closure. Calls on `.touchUpInside` |
183197
| `identifier` | `String` | `""` | Identifier for `ExpandableButtonItem`. |
184198

185199

186-
You can also use [`ArrowButton`](ExpandableButton/ArrowButton.swift) (button which can drow left and right arrow using core graphics, just call `showLeftArrow()` or `showRightArrow()`) and [`ActionButton`](ExpandableButton/ActionButton.swift) (simple `UIButton` but with `actionBlock` propertie which calls on `.touchUpInside`) in your projects.
200+
You can also use [`ArrowButton`](ExpandableButton/ArrowButton.swift) (button which can drow left, right, up and down arrows using core graphics, just call `showLeftArrow()`, `showRightArrow()`, `showUpArrow()` or `showDownArrow()`) and [`ActionButton`](ExpandableButton/ActionButton.swift) (simple `UIButton` but with `actionBlock` propertie which calls on `.touchUpInside`) in your projects.
187201

188202
## License
189203
**ExpandableButton** is under MIT license. See the [LICENSE](LICENSE) file for more info.

0 commit comments

Comments
 (0)