Skip to content

Simple Circle Button (Swift)

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

Add simple circle buttons with just an image for each to BMB.

Swift | Objective-C

Create BMB

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 = .simpleCircle
bmb.piecePlaceEnum = .dot_3_1
bmb.buttonPlaceEnum = .sc_3_1

For more information and pictures about piece-place-enum and button-place-enum, check the lists below.

Add Builders

The builder of simple circle 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 _ in 0..<bmb.piecePlaceEnum.pieceNumber() {
    let builder = SimpleCircleButtonBuilder.init()
    builder.normalImageName = "butterfly"
    bmb.addBuilder(builder)
}

In the above loop, the value of bmb.piecePlaceEnum.pieceNumber() is 3, because the piecePlaceEnum is set to .dot_3_1. So we provide 3 builders for the 3 boom-buttons, with the same image butterfly.

If you wanna customize more properties for boom-buttons:

for _ in 0..<bmb.piecePlaceEnum.pieceNumber() {
    let builder = SimpleCircleButtonBuilder.init()
    
    // Event closure when the boom-button corresponding the builder itself is clicked.
    builder.clickedClosure = { (index: Int) -> Void in
        // the boom-button is clicked
    }
    
    // Whether the boom-button is unable (for click event). The default value is false.
    builder.unable = false
    
    // Whether the image in boom-button plays a rotation animation.
    builder.rotateImage = false

Piece

    // 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.white

Shadow

    // Whether the boom-button has a shadow effect.
    builder.hasShadow = true
    
    // The rect of shadow path of boom-button.
    builder.shadowPathRect = CGRect.init(x: 2, y: 2, width: 76, height: 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.darkGray

Image

    // 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.init(named: "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.init(named: "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.init(named: "bat")
    
    // The tint color of image on boom-button at normal state.
    builder.normalImageTintColor = UIColor.red
    
    // The tint color of image on boom-button at highlighted state.
    builder.highlightedImageTintColor = UIColor.yellow
    
    // The tint color of image on boom-button at unable state.
    builder.unableImageTintColor = UIColor.blue
    
    // The frame of the image view on boom-button.
    builder.imageFrame = CGRect.init(x: 10, y: 10, width: 60, height: 60)
    
    // The image size of the image view on boom-button.
    builder.imageSize = CGSize.init(width: 60, height: 60)

Button

    // The color of boom-button at normal state.
    builder.normalColor = UIColor.white
    
    // The color of boom-button at highlighted state.
    builder.highlightedColor = UIColor.green
    
    // The color of boom-button at unable state.
    builder.unableColor = UIColor.black
    
    // The corner radius (in points) of boom-button.
    builder.cornerRadius = 5
    
    // The radius (in points) of the circular (or square) button.
    builder.radius = 40
    
    // Whether the boom-button is in a circular shape. If not, then the simple-circle-button 
    // looks like a simple-square-button. Only after the 'round' property is false does 
    // the corner-radius property work.
    builder.round = true
    
    bmb.addBuilder(builder)
}

Piece Place Enum for Simple Circle Button

All piece-place-enum and button-place-enum can be found in demo.

  1. PiecePlaceEnum.dot_1
  2. PiecePlaceEnum.dot_2_m
  3. PiecePlaceEnum.dot_3_m
  4. PiecePlaceEnum.dot_4_m
  5. PiecePlaceEnum.dot_5_m
  6. PiecePlaceEnum.dot_6_m
  7. PiecePlaceEnum.dot_7_m
  8. PiecePlaceEnum.dot_8_m
  9. PiecePlaceEnum.dot_9_m
  10. PiecePlaceEnum.share
    PiecePlaceEnum.share places the pieces as a share-style on BMB. Check the demo and wiki for more information.
  11. PiecePlaceEnum.custom
    PiecePlaceEnum.custom enables developers to customize the number and the positions of boom-buttons. Check the demo and wiki for more information.

Button Place Enum for Simple Circle Button

All piece-place-enum and button-place-enum can be found in demo.

  1. ButtonPlaceEnum.sc_1
  2. ButtonPlaceEnum.sc_2_m
  3. ButtonPlaceEnum.sc_3_m
  4. ButtonPlaceEnum.sc_4_m
  5. ButtonPlaceEnum.sc_5_m
  6. ButtonPlaceEnum.sc_6_m
  7. ButtonPlaceEnum.sc_7_m
  8. ButtonPlaceEnum.sc_8_m
  9. ButtonPlaceEnum.sc_9_m
  10. ButtonPlaceEnum.horizontal
    ButtonPlaceEnum.horizontal place all the boom-buttons in a horizontal line.
  11. ButtonPlaceEnum.vertical
    ButtonPlaceEnum.vertical place all the boom-buttons in a vertical line.
  12. ButtonPlaceEnum.custom
    ButtonPlaceEnum.custom enables developers to customize the number and the positions of boom-buttons. Check the demo and wiki for more information.

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