ExpandableButton
Customizable and easy to use expandable button in Swift.
Requirements
- iOS 9.0+
Installation
CocoaPods:
- Add the following line to your
Podfile
:
- Add
use_frameworks!
to yourPodfile
. - Run
pod install
. - Add to files:
Usage
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.
Diretions example:
Items with image
and action
:
With image
, highlightedImage
, imageEdgeInsets
:
arrowWidth
, separatorWidth
and cornerRadius
:
Custom icons for open
and close
actions, closeOpenImagesInsets
:
With attributedTitle
, highlightedAttributedTitle
and custom item size
:
With attributedTitle
under image
(using contentEdgeInsets
, titleEdgeInsets
, imageEdgeInsets
, titleAlignment
, imageContentMode
, size
):
You can also open()
and close()
:
All options
ExpandableButtonView
Name | Type | Default value | Description |
---|---|---|---|
direction |
Direction |
.right |
Opening direction. Could be .left , .right , .up , .down . Set only on init(frame:direction:items:) . |
state |
State |
.closed |
Current state. Could be .opened , .closed or .animating . |
animationDuration |
TimeInterval |
0.2 |
Opening, closing and arrow animation duration. |
closeOnAction |
Bool |
false |
If true call close() after any item action. |
isHapticFeedback |
Bool |
true |
Turn on haptic feedback (Taptic engine) |
arrowInsets |
UIEdgeInsets |
top: 12 left: 12 bottom: 12 right: 12 |
Arrow insets. |
arrowWidth |
CGFloat |
1 |
Arrow line width. |
arrowColor |
UIColor |
UIColor.black |
Arrow color. |
closeOpenImagesInsets |
UIEdgeInsets |
.zero |
Insets for custom close and open images. |
closeImage |
UIImage? |
nil |
Custom close image. |
openImage |
UIImage? |
nil |
Custom open image. |
isSeparatorHidden |
Bool |
false |
If true hide separator view. |
separatorColor |
UIColor |
UIColor.black |
Separator color. |
separatorInset |
CGFloat |
8 |
Separator inset from top, bottom for .left , .right directions and from left, right for up , down . |
separatorWidth |
CGFloat |
1 |
Separator view width. |
ExpandableButtonItem
Name | Type | Default value | Description |
---|---|---|---|
image |
UIImage? |
nil |
Image for .normal state. |
highlightedImage |
UIImage? |
nil |
Image for .highlighted state. |
attributedTitle |
NSAttributedString? |
nil |
Attributed string for .normal state. |
highlightedAttributedTitle |
NSAttributedString? |
nil |
Attributed string for .highlighted state. |
contentEdgeInsets |
UIEdgeInsets |
.zero |
contentEdgeInsets for UIButton |
titleEdgeInsets |
UIEdgeInsets |
.zero |
titleEdgeInsets for UIButton . |
imageEdgeInsets |
UIEdgeInsets |
.zero |
imageEdgeInsets for UIButton . |
size |
CGSize? |
nil |
UIButton size for current item. If nil will be equal to arrow button size. |
titleAlignment |
NSTextAlignment |
.center |
titleAlignment for titleLabel in UIButton . |
imageContentMode |
UIViewContentMode |
.scaleAspectFit |
imageContentMode for imageView in UIButton . |
action |
(ExpandableButtonItem) -> Void |
{_ in} |
Action closure. Calls on .touchUpInside |
identifier |
String |
"" |
Identifier for ExpandableButtonItem . |