- Notifications
You must be signed in to change notification settings - Fork16
Customizable and easy to use expandable button in Swift.
License
DimaMishchenko/ExpandableButton
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
- iOS 9.0+
- Add the following line to your
Podfile
:
pod'ExpandableButton'#for swift less than 4.2 use:pod'ExpandableButton','~> 1.0.0'
- Add
use_frameworks!
to yourPodfile
. - Run
pod install
. - Add to files:
import ExpandableButton
You can initExpandableButton withframe
(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:
letrightButton=ExpandableButtonView(frame: frame, direction:.right, items: items)letleftButton=ExpandableButtonView(frame: frame, direction:.left, items: items)letupButton=ExpandableButtonView(frame: frame, direction:.up, items: items)letdownButton=ExpandableButtonView(frame: frame, direction:.down, items: items)
Items withimage
andaction
:
// create items with images and actionsletitems=[ExpandableButtonItem( image:UIImage(named:"delete"), action:{_inprint("delete")}),ExpandableButtonItem( image:UIImage(named:"edit"), action:{_inprint("edit")}),ExpandableButtonItem( image:UIImage(named:"share"), action:{ _inprint("share")})] // create ExpandableButtonletbuttonView=ExpandableButtonView(items: items)buttonView.frame=CGRect(x:0, y:0, width:60, height:60)buttonView.backgroundColor=.whiteview.addSubview(buttonView)
Withimage
,highlightedImage
,imageEdgeInsets
:
letinsets=UIEdgeInsets(top:16, left:16, bottom:16, right:16) // create items with image, highlighted image, image insets.letitems=[ExpandableButtonItem( image:UIImage(named:"delete"), highlightedImage:UIImage(named:"highlightedDelete"), imageEdgeInsets: insets, action:{_inprint("delete")})...]
arrowWidth
,separatorWidth
andcornerRadius
:
buttonView.arrowWidth=2buttonView.separatorWidth=2buttonView.layer.cornerRadius=30
Custom icons foropen
andclose
actions,closeOpenImagesInsets
:
// custom open and close imagesbuttonView.openImage=UIImage(named:"open")buttonView.closeImage=UIImage(named:"close")buttonView.closeOpenImagesInsets= insets
WithattributedTitle
,highlightedAttributedTitle
and custom itemsize
:
// with attributed string, highlighted attributed string, custom size.letitems=[ExpandableButtonItem( attributedTitle:NSAttributedString( string:"Attributed Text", attributes:[.foregroundColor:UIColor.red]), highlightedAttributedTitle:NSAttributedString( string:"Attributed Text", attributes:[.foregroundColor:UIColor.green]), size:CGSize(width:160, height:60))]
WithattributedTitle
underimage
(usingcontentEdgeInsets
,titleEdgeInsets
,imageEdgeInsets
,titleAlignment
,imageContentMode
,size
):
letattributedTitle=NSAttributedString( string:"Share", attributes:[.foregroundColor:UIColor.black,.font:UIFont.systemFont(ofSize:12)])lethighlightedAttributedTitle=NSAttributedString( string:"Share", attributes:[.foregroundColor:UIColor.lightGray,.font:UIFont.systemFont(ofSize:12)])letitems=[ExpandableButtonItem( image:UIImage(named:"share"), highlightedImage:UIImage(named:"haglightedShare"), attributedTitle: attributedTitle, highlightedAttributedTitle: highlightedAttributedTitle, contentEdgeInsets:UIEdgeInsets(top:6, left:6, bottom:6, right:6), titleEdgeInsets:UIEdgeInsets(top:24, left:-200, bottom:0, right:0), imageEdgeInsets:UIEdgeInsets(top:6, left:0, bottom:24, right:0), size:CGSize(width:80, height:60), titleAlignment:.center, imageContentMode:.scaleAspectFit)]
You can alsoopen()
andclose()
:
letbuttonView=ExpandableButtonView(items: items)buttonView.open() buttonView.close()
Name | Type | Default value | Description |
---|---|---|---|
direction | Direction | .right | Opening direction. Could be.left ,.right ,.up ,.down . Set only oninit(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 | Iftrue callclose() 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 | Iftrue 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 forup ,down . |
separatorWidth | CGFloat | 1 | Separator view width. |
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 forUIButton |
titleEdgeInsets | UIEdgeInsets | .zero | titleEdgeInsets forUIButton . |
imageEdgeInsets | UIEdgeInsets | .zero | imageEdgeInsets forUIButton . |
size | CGSize? | nil | UIButton size for current item. Ifnil will be equal to arrow button size. |
titleAlignment | NSTextAlignment | .center | titleAlignment fortitleLabel inUIButton . |
imageContentMode | UIViewContentMode | .scaleAspectFit | imageContentMode forimageView inUIButton . |
action | (ExpandableButtonItem) -> Void | {_ in} | Action closure. Calls on.touchUpInside |
identifier | String | "" | Identifier forExpandableButtonItem . |
You can also useArrowButton
(button which can drow left, right, up and down arrows using core graphics, just callshowLeftArrow()
,showRightArrow()
,showUpArrow()
orshowDownArrow()
) andActionButton
(simpleUIButton
but withactionBlock
propertie which calls on.touchUpInside
) in your projects.
ExpandableButton is under MIT license. See theLICENSE file for more info.
About
Customizable and easy to use expandable button in Swift.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.