Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/smartapps-fr/DDExpandableButton

A single-file iOS 5.0+ class designed to be used like an expandable UIButton ; as seen in the iOS Camera app for the "flash" button.
https://github.com/smartapps-fr/DDExpandableButton

Last synced: about 1 month ago
JSON representation

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

Awesome Lists containing this project

README

        

DDExpandableButton
==============

Purpose
--------------

`DDExpandableButton` is a single-file iOS 5.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](https://github.com/iosdeveloper/ExpandyButton).*

![button samples](http://github.com/ddebin/DDExpandableButton/raw/master/README.png)

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.