-
Notifications
You must be signed in to change notification settings - Fork 112
Ham Button (Objective C)
Add ham buttons with with a text, sub-text and image inside for each to BMB.
Swift | Objective-C
As mentioned in Basic Usage, BMB must know the kind of boom-buttons and how it should place the boom-buttons on itself and screen.
bmb.buttonEnum = VHButtonHam;
bmb.piecePlaceEnum = VHPiecePlaceHAM_1;
bmb.buttonPlaceEnum = VHButtonPlaceHAM_1;
For more information and pictures about piece-place-enum and button-place-enum, check the lists below.
The builder of ham button has lots of methods to customize the boom-buttons. Needn't to set every attributes for boom-buttons, just customize what you want. For example:
for (int i = 0; i < bmb.pieceNumber; i++)
{
VHHamButtonBuilder *builder = [VHHamButtonBuilder builder];
builder.normalImageName = @"butterfly";
builder.normalText = @"Text Outside";
builder.normalSubText = @"Sub Text";
[self.bmb addBuilder:builder];
}
In the above loop, the value of bmb.pieceNumber
is 3
, because the piecePlaceEnum
is set to VHPiecePlaceHAM_1
. So we provide 3
builders for the 3
boom-buttons, with the same image butterfly
, same text Text
and same sub-text Sub Text
.
If you wanna customize more properties for boom-buttons:
for (int i = 0; i < self.bmb.pieceNumber; i++)
{
VHHamButtonBuilder *builder = [VHHamButtonBuilder builder];
// Event block when the boom-button corresponding the builder itself is clicked.
builder.clickedBlock = ^(int index) {
// the boom-button is clicked
};
// Whether the boom-button is unable (for click event).
builder.unable = NO;
// Whether the image in boom-button plays a rotation animation.
builder.rotateImage = YES;
// The color of the corresponding piece.
// If the color of piece is nil (by default), then BMB will use the color of boom-button
// at normal state (if the boom-buttons is unable, then use color at unable state) to draw the piece.
// If the color of piece is different from boom-button's, then BMB will play a discoloration
// animation when booming or rebooming.
builder.pieceColor = UIColor.whiteColor;
// Whether the boom-button has a shadow effect.
builder.hasShadow = YES;
// The rect of shadow path of boom-button.
builder.shadowPathRect = CGRectMake(2, 2, 76, 76);
// The offset (in points) of shadow in x axis.
builder.shadowOffsetX = 0;
// The offset (in points) of shadow in y axis.
builder.shadowOffsetY = 8;
// The blur radius (in points) used to render the boom-button's shadow.
builder.shadowRadius = 4;
// The color of the boom-button's shadow.
builder.shadowColor = UIColor.darkGrayColor;
// The name of the image on the boom-button at normal state.
builder.normalImageName = @"butterfly";
// The image on the boom-button at normal state.
builder.normalImage = [UIImage imageNamed:@"butterfly"];
// The name of the image on the boom-button at highlighted state.
builder.highlightedImageName = @"bear";
// The image on the boom-button at highlighted state.
builder.highlightedImage = [UIImage imageNamed:@"bear"];
// The name of the image on the boom-button at unable state.
builder.unableImageName = @"bat";
// The image on the boom-button at unable state.
builder.unableImage = [UIImage imageNamed:@"bat"];
// The tint color of image on boom-button at normal state.
builder.normalImageTintColor = UIColor.redColor;
// The tint color of image on boom-button at highlighted state.
builder.highlightedImageTintColor = UIColor.yellowColor;
// The tint color of image on boom-button at unable state.
builder.unableImageTintColor = UIColor.blueColor;
// The frame of the image view on boom-button.
builder.imageFrame = CGRectMake(10, 10, 60, 60);
// The image size of the image view on boom-button.
builder.imageSize = CGSizeMake(60, 60);
// The text on boom-button at normal state.
builder.normalText = @"Text Outside";
// The text on boom-button at highlighted state.
builder.highlightedText = @"Highlighted Text";
// The text on boom-button at unable state.
builder.unableText = @"Unable";
// The attributed text on boom-button at normal state.
builder.normalAttributedText = [[NSAttributedString alloc] initWithString:@"Text"];
// The attributed text on boom-button at highlighted state.
builder.highlightedAttributedText = [[NSAttributedString alloc] initWithString:@"Text"];
// The attributed text on boom-button at unable state.
builder.unableAttributedText = [[NSAttributedString alloc] initWithString:@"Text"];
// The color of text on boom-button at normal state.
builder.normalTextColor = [UIColor whiteColor];
// The color of text on boom-button at highlighted state.
builder.highlightedTextColor = [UIColor yellowColor];
// The color of text on boom-button at unable state.
builder.unableTextColor = [UIColor darkGrayColor];
// The frame of text on boom-button.
builder.textFrame = CGRectMake(15, 52, 50, 20);
// The font of text on boom-button.
builder.textFont = [UIFont systemFontOfSize:10];
// The alignment of text on boom-button.
builder.textAlignment = NSTextAlignmentCenter;
// The line break mode of text on boom-button.
builder.textLineBreakMode = NSLineBreakByCharWrapping;
// The maximum number of lines to use for text on boom-button.
builder.textLines = 2;
// The color of shadow for text on boom-button.
builder.textShadowColor = [UIColor darkGrayColor];
// The shadow offset (in points) on x axis for text on boom-button.
builder.textShadowOffsetX = 2;
// The shadow offset (in points) on y axis for text on boom-button.
builder.textShadowOffsetY = 2;
// Whether the boom-button contains a sub-text. All properties for sub-text only work when "containsSubText" is true.
builder.containsSubText = YES;
// The sub-text on boom-button at normal state.
builder.normalSubText = @"Sub Text";
// The sub-text on boom-button at highlighted state.
builder.highlightedSubText = @"Sub Text";
// The sub-text on boom-button at unable state.
builder.unableSubText = @"Sub Text";
// The attributed sub-text on boom-button at normal state.
builder.normalAttributedSubText = [[NSAttributedString alloc] initWithString:@"Text"];
// The attributed sub-text on boom-button at highlighted state.
builder.highlightedAttributedSubText = [[NSAttributedString alloc] initWithString:@"Text"];
// The attributed sub-text on boom-button at unable state.
builder.unableAttributedSubText = [[NSAttributedString alloc] initWithString:@"Text"];
// The color of sub-text on boom-button at normal state.
builder.normalSubTextColor = [UIColor whiteColor];
// The color of sub-text on boom-button at highlighted state.
builder.highlightedSubTextColor = [UIColor yellowColor];
// The color of sub-text on boom-button at unable state.
builder.unableSubTextColor = [UIColor darkGrayColor];
// The frame of sub-text on boom-button.
builder.subTextFrame = CGRectMake(70, 35, 220, 15);
// The font of sub-text on boom-button.
builder.subTextFont = [UIFont systemFontOfSize:9];
// The alignment of sub-text on boom-button.
builder.subTextAlignment = NSTextAlignmentLeft;
// The line break mode of sub-text on boom-button.
builder.subTextLineBreakMode = NSLineBreakByTruncatingTail;
// The maximum number of lines to use for sub-text on boom-button.
builder.subTextLines = 1;
// The color of shadow for sub-text on boom-button.
builder.subTextShadowColor = [UIColor darkGrayColor];
// The shadow offset (in points) on x axis for sub-text on boom-button.
builder.subTextShadowOffsetX = 2;
// The shadow offset (in points) on y axis for sub-text on boom-button.
builder.subTextShadowOffsetY = 2;
// The color of boom-button at normal state.
builder.normalColor = UIColor.whiteColor;
// The color of boom-button at highlighted state.
builder.highlightedColor = UIColor.greenColor;
// The color of boom-button at unable state.
builder.unableColor = UIColor.blackColor;
// The corner radius (in points) of boom-button.
builder.cornerRadius = 5;
// Width (in points) of the boom-button (including the text label).
builder.width = 300;
// Height (in points) of the boom-button (including the text label).
builder.height = 60;
[self.bmb addBuilder:builder];
}
All piece-place-enum and button-place-enum can be found in demo.
-
VHPiecePlaceHAM_1
-
VHPiecePlaceHAM_2
-
VHPiecePlaceHAM_3
-
VHPiecePlaceHAM_4
-
VHPiecePlaceHAM_5
-
VHPiecePlaceHAM_6
-
VHPiecePlaceCustom
VHPiecePlaceCustom
enables developers to customize the number and the positions of boom-buttons. Check the demo and wiki for more information.
All piece-place-enum and button-place-enum can be found in demo.
-
VHButtonPlaceHAM_1
-
VHButtonPlaceHAM_2
-
VHButtonPlaceHAM_3
-
VHButtonPlaceHAM_4
-
VHButtonPlaceHAM_5
-
VHButtonPlaceHAM_6
-
VHButtonPlaceHorizontal
VHButtonPlaceHorizontal
place all the boom-buttons in a horizontal line.
-
VHButtonPlaceVertical
VHButtonPlaceVertical
place all the boom-buttons in a vertical line.
-
VHButtonPlaceCustom
VHButtonPlaceCustom
enables developers to customize the number and the positions of boom-buttons. Check the demo and wiki for more information.
Sometimes we need to add a boom-button with "Cancel" on the last boom-button(the bottom one). And maybe the last one should have a larger top-margin with its above one. Then you can set this special attribute by:
bmb.bottomHamButtonTopMargin = 30;
Home
Chapters
- Basic Usage
- Simple Circle Button
- Text Inside Circle Button
- Text Outside Circle Button
- Ham Button
- Share Style
- Custom Position
- Button Place Alignments
- Different Ways to Boom
- Ease Animations for Buttons
- Different Order for Buttons
- Other Animations Attributes for Buttons
- Click Event and Listener
- Control BMB
- Use BMB in Navigation Bar
- Use BMB in Table View
- Attributes for BMB or Pieces on BMB
- Cache Optimization & Boom Area
- Change Boom Buttons Dynamically
- Blur Background & Tip
- Fade Views
- Structure of BMB
- Version History