A custom UIButton inspired by the "radial menu" that displays any number of subordinate buttons ("leaf buttons") when tapped and held.
It's designed to be a drop-in replacement for UIButton, supporting UIControlEvent
for user-interaction and UIControlState
for controlling its changes in appearance. Thus it supports being used and configured from Interface-Builder as well as directly from code.
A simple interactive demo project is included.
Creating a button via code can be accomplished as follows:
RSExplodingButton *button = [RSExplodingButton alloc] initWithFrame:frame];
[self.view addSubview:button];
Adding a leaf button is done through instance methods that duplicates the appearance of the root button. As with standard UIButton controls, a leaf button will require a method selector to be provided for responding to touch events:
for (int i = 0; i < numberOfButtonsDesired; i++)
{
RSExplodingButton *button = [self.explodingButton addButtonWithTitle:[NSString stringWithFormat:@"%d", i+1]];
[button addTarget:self action:@selector(didTouchUpButton:) forControlEvents:UIControlEventTouchUpInside];
}
By default, the button assumes the tintColor
property as the fill color for its highlighted state and the backgroundColor
as the fill color for its normal state. When the button is highlighted, the colors inverse.
The button appearance can be customized in the following ways:
setDefaultColor:
will update the background color of the button forUIControlStateNormal
setHighlightColor:
will update the tint color forUIControlStateNormal
and the background color forUIControlStateHighlighted