X.BOZO X.BOZO - 7 months ago 8
Swift Question

how can make BubbleMenu Button as Action?

i have code to do BubbleMenu Button

i got it from somewhere

and i want to make BubbleMenu as Action but i can't do it

for example "A" = LogOut , and "B" = LogIn or anything

can someone help me ?

here is the code

//
// ViewController.swift
// DWBubbleMenuButton.Swift
//
// Created by feiin on 14/10/25.
// Copyright (c) 2014 year swiftmi. All rights reserved.
//

import UIKit


class ViewController: UIViewController {



var upMenuView:DWBubbleMenuButton!

override func viewDidLoad() {
super.viewDidLoad()


// Do any additional setup after loading the view, typically from a nib.
}

@IBAction func hiddenAll(sender: AnyObject) {
print("ok")

upMenuView.dismissButtons()

}
override func viewDidAppear(animated: Bool) {


// Create up menu button
let homeLabel2 = self.createHomeButtonView()

upMenuView = DWBubbleMenuButton(frame: CGRectMake(self.view.frame.size.width - homeLabel2.frame.size.width - 20.0,self.view.frame.size.height - homeLabel2.frame.size.height - 20.0,
homeLabel2.frame.size.width,homeLabel2.frame.size.height),expansionDirection: .DirectionUp)
upMenuView.homeButtonView = homeLabel2

upMenuView.addButtons(self.createDemoButtonArray())

self.view.addSubview(upMenuView)

}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

func createHomeButtonView() -> UILabel {

let label = UILabel(frame: CGRectMake(0.0, 0.0, 40.0, 40.0))

label.text = "Tap";
label.textColor = UIColor.whiteColor()
label.textAlignment = NSTextAlignment.Center
label.layer.cornerRadius = label.frame.size.height / 2.0;
label.backgroundColor = UIColor(red:0.0,green:0.0,blue:0.0,alpha:0.5)
label.clipsToBounds = true;

return label;
}

func createDemoButtonArray() -> [UIButton] {
var buttons:[UIButton]=[]
var i = 0
for str in ["A","B","C","D","E","F"] {
let button:UIButton = UIButton(type: UIButtonType.System)
button.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
button.setTitle(str, forState: UIControlState.Normal)

button.frame = CGRectMake(0.0, 0.0, 30.0, 30.0);
button.layer.cornerRadius = button.frame.size.height / 2.0;
button.backgroundColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.5)
button.clipsToBounds = true;
i += 1


buttons.append(button)

}
return buttons

}





}


enter image description here

Answer

you mean like this?

    func createDemoButtonArray() -> [UIButton] {
    var buttons:[UIButton]=[]
    var i = 0
    for str in ["A","B","C","D","E","F"] {
        let button:UIButton = UIButton(type: UIButtonType.System)
        button.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
        button.setTitle(str, forState: UIControlState.Normal)

        button.frame = CGRectMake(0.0, 0.0, 30.0, 30.0);
        button.layer.cornerRadius = button.frame.size.height / 2.0;
        button.backgroundColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.5)
        button.clipsToBounds = true;
        i += 1
        buttons.append(button)
        if button.currentTitle == "A" {
            button.addTarget(self, action: Selector("login"), forControlEvents: UIControlEvents.TouchUpInside)
        }
        if button.currentTitle == "B" {
            button.addTarget(self, action: Selector("logout"), forControlEvents: UIControlEvents.TouchUpInside)
        }
    }
    return buttons
}
Comments