Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Customizable and easy to use expandable button in Swift.

License

NotificationsYou must be signed in to change notification settings

DimaMishchenko/ExpandableButton

Repository files navigation

Swift 4.2CocoaPods compatiblePackagist

Requirements

  • iOS 9.0+

Installation

  • Add the following line to yourPodfile:
pod'ExpandableButton'#for swift less than 4.2 use:pod'ExpandableButton','~> 1.0.0'
  • Adduse_frameworks! to yourPodfile.
  • Runpod install.
  • Add to files:
import ExpandableButton

Usage

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()

All options

NameTypeDefault valueDescription
directionDirection.rightOpening direction. Could be.left,.right,.up,.down. Set only oninit(frame:direction:items:).
stateState.closedCurrent state. Could be.opened,.closed or.animating.
animationDurationTimeInterval0.2Opening, closing and arrow animation duration.
closeOnActionBoolfalseIftrue callclose() after any item action.
isHapticFeedbackBooltrueTurn on haptic feedback (Taptic engine)
arrowInsetsUIEdgeInsetstop: 12 left: 12 bottom: 12 right: 12Arrow insets.
arrowWidthCGFloat1Arrow line width.
arrowColorUIColorUIColor.blackArrow color.
closeOpenImagesInsetsUIEdgeInsets.zeroInsets for custom close and open images.
closeImageUIImage?nilCustom close image.
openImageUIImage?nilCustom open image.
isSeparatorHiddenBoolfalseIftrue hide separator view.
separatorColorUIColorUIColor.blackSeparator color.
separatorInsetCGFloat8Separator inset from top, bottom for.left,.right directions and from left, right forup,down.
separatorWidthCGFloat1Separator view width.
NameTypeDefault valueDescription
imageUIImage?nilImage for.normal state.
highlightedImageUIImage?nilImage for.highlighted state.
attributedTitleNSAttributedString?nilAttributed string for.normal state.
highlightedAttributedTitleNSAttributedString?nilAttributed string for.highlighted state.
contentEdgeInsetsUIEdgeInsets.zerocontentEdgeInsets forUIButton
titleEdgeInsetsUIEdgeInsets.zerotitleEdgeInsets forUIButton.
imageEdgeInsetsUIEdgeInsets.zeroimageEdgeInsets forUIButton.
sizeCGSize?nilUIButton size for current item. Ifnil will be equal to arrow button size.
titleAlignmentNSTextAlignment.centertitleAlignment fortitleLabel inUIButton.
imageContentModeUIViewContentMode.scaleAspectFitimageContentMode forimageView inUIButton.
action(ExpandableButtonItem) -> Void{_ in}Action closure. Calls on.touchUpInside
identifierString""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.

License

ExpandableButton is under MIT license. See theLICENSE file for more info.

About

Customizable and easy to use expandable button in Swift.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp