Skip to content

A single-file iOS 3+ class designed to be used like an expandable UIButton ; as seen in the iOS Camera app for the "flash" button.

License

Notifications You must be signed in to change notification settings

bluesuedesw/DDExpandableButton

This branch is up to date with kwongius/DDExpandableButton:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

c360a71 · Jun 21, 2013

History

35 Commits
Jun 21, 2013
Jun 21, 2013
Jun 21, 2013
Jun 13, 2013
Jun 21, 2013
Jun 13, 2013
Jun 13, 2013
Jun 13, 2013
Oct 1, 2012
May 13, 2013
Aug 1, 2011

Repository files navigation

DDExpandableButton

Purpose

DDExpandableButton is a single-file iOS 3.0+ non-ARC class (ARC compatible) designed to be used like an expandable UIButton ; as seen in the iOS Camera app for the flash button.

Originally inspired by ExpandyButton.

button samples

Properties

A DDExpandableButton has the following properties:

  • @property (nonatomic,assign) BOOL expanded; Current button status (if expanded or shrunk).

  • @property (nonatomic,assign) BOOL useAnimation; Use animation during button state transitions.

  • @property (nonatomic,assign) BOOL toggleMode; Use button as a toggle (like "HDR On" / "HDR Off" button in camera app).

  • @property (nonatomic,assign) CGFloat timeout; To shrink the button after a timeout. Use 0 if you want to disable timeout.

  • @property (nonatomic,assign) CGFloat horizontalPadding; Horizontal padding space between items.

  • @property (nonatomic,assign) CGFloat verticalPadding; Vertical padding space above and below items.

  • @property (nonatomic,assign) CGFloat borderWidth; Width (thickness) of the button border.

  • @property (nonatomic,assign) CGFloat innerBorderWidth; Width (thickness) of the inner borders between items.

  • @property (nonatomic,assign) NSUInteger selectedItem; Selected item number.

  • @property (nonatomic,retain) UIColor *borderColor; Color of the button and inner borders.

  • @property (nonatomic,retain) UIColor *textColor; Color of text labels.

  • @property (nonatomic,retain) UIFont *labelFont; Font of text labels.

  • @property (nonatomic,retain) UIFont *unSelectedLabelFont; Font of unselected text labels. Nil if not different from labelFont.

  • @property (nonatomic,readonly) NSArray *labels; Access UIView used to draw labels.

Methods

A DDExpandableButton has the following methods:

  • - (id)initWithPoint:(CGPoint)point leftTitle:(id)leftTitle buttons:(NSArray *)buttons; Init method where you can specify leftTitle and buttons.

  • - (void)setSelectedItem:(NSUInteger)selected animated:(BOOL)animated; Animated version of - (void)setSelectedItem:(NSUInteger)selected.

  • - (void)setExpanded:(BOOL)expanded animated:(BOOL)animated; Animated version of - (void)setExpanded:(BOOL)expanded.

  • - (void)setLeftTitle:(id)leftTitle; Set left title view : you can use a NSString, an UIImage or any UIView (but the view must implement DDExpandableButtonViewSource protocol).

  • - (void)setButtons:(NSArray *)buttons; Set buttons views : you can use a NSString, an UIImage or any UIView (but the view must implement DDExpandableButtonViewSource protocol).

  • - (void)disableTimeout; If you want to disable timeout shrunk. You can set timeout to 0 also.

  • - (void)updateDisplay; When modifying button parameters, use this method to update button display.

Protocols

The DDExpandableButtonViewSource protocol, used when you specify the title or the different buttons, has the following methods:

  • - (CGSize)defaultFrameSize; Returns default frame size of the view, used when expanding the button.

  • - (void)setHighlighted:(BOOL)highlighted; Optional, used to change appearance of selected items.

Usage

Example : a button with four text labels and a hook when value change.

NSArray *buttons = [NSArray arrayWithObjects:@"Black", @"Red", @"Green", @"Blue", nil];
DDExpandableButton *colorButton = [[[DDExpandableButton alloc] initWithPoint:CGPointMake(20, 70) leftTitle:@"Color" buttons:buttons] autorelease];
[[self view] addSubview:colorButton];
[colorButton addTarget:self action:@selector(toggleColor:) forControlEvents:UIControlEventValueChanged];

License

DDExpandableButton is available under the MIT license. See the LICENSE file for more info.

About

A single-file iOS 3+ class designed to be used like an expandable UIButton ; as seen in the iOS Camera app for the "flash" button.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 97.6%
  • Ruby 2.4%