Skip to content

Basic Usage (Swift)

Weiping Huang edited this page May 9, 2017 · 2 revisions

How to use BMB in just several lines of code?

Swift | Objective-C

Create BMB

From version 2.0.0, BMB can be used directly in .storyboard or .xib. Add a view to view-controller and then change the Class to BoomMenuButton and change the Module to VHBoomMenuButton in identity inspector. Of course, BMB can be also added by frame-initialization method:

var bmb = BoomMenuButton.init(frame: CGRect.init(x: 0, y: 0, width: 60, height: 60))

And, don't forget to import BMB:

import VHBoomMenuButton

After adding a BMB in your view-controller, now you should tell BMB what kind of boom-buttons(the sub-buttons when booming) that you expect to boom by setting ButtonEnum property.

  1. ButtonEnum.simpleCircle corresponding to Simple Circle Button
  2. ButtonEnum.textInsideCircle corresponding to Text Inside Circle Button
  3. ButtonEnum.textOutsideCircle corresponding to Text Outside Circle Button
  4. ButtonEnum.ham corresponding to Ham Button
bmb.buttonEnum = .simpleCircle

Then you need to tell BMB how it should place pieces on itself. Click the links for 4 kinds of buttons above to check different piece-place-enums.

bmb.piecePlaceEnum = .dot_3_1

Now tell BMB how to place the buttons on the screen when booming. Click the links for 4 kinds of buttons above to check different button-place-enums.

bmb.buttonPlaceEnum = .sc_3_3

Add Builders

You have set enough properties for BMB itself, now add builders for customizing boom-buttons to BMB. There are 4 different builders for the 4 kinds of boom-buttons above. For instance, use SimpleCircleButtonBuilder for ButtonEnum.simpleCircle. Click the links for 4 kinds of buttons above to find out how to use builders.

for _ in 0..<bmb.piecePlaceEnum.pieceNumber() {
    let builder = SimpleCircleButtonBuilder.init()
    builder.normalImageName = "PictureName"
    bmb.addBuilder(builder)
}

And now your BMB is ready for a boom.

Attention

You must keep the number of piece-place-enum, number of button-place-enum and number of builders being the same.

The name of piece-place-enum is xxx_n_m, where xxx is name(dot or ham), n is number and m represents different types. Similarly, the name of button-place-enum is yyy_n_m. You must keep the first n equals to the second one. But you needn't keep the two m same(The code above is an example: dot_3_1 and sc_3_3). Unless the piece-place-enum is share or custom. Check Share Style and Custom Position for more details.

And the number of builders must be n. Any breaking-rules-code will get an assert.

Home
Chapters

  1. Basic Usage
  2. Simple Circle Button
  3. Text Inside Circle Button
  4. Text Outside Circle Button
  5. Ham Button
  6. Share Style
  7. Custom Position
  8. Button Place Alignments
  9. Different Ways to Boom
  10. Ease Animations for Buttons
  11. Different Order for Buttons
  12. Other Animations Attributes for Buttons
  13. Click Event and Listener
  14. Control BMB
  15. Use BMB in Navigation Bar
  16. Use BMB in Table View
  17. Attributes for BMB or Pieces on BMB
  18. Cache Optimization & Boom Area
  19. Change Boom Buttons Dynamically
  20. Blur Background & Tip
  21. Fade Views
  22. Structure of BMB
  23. Version History
Clone this wiki locally