jdg / MBProgressHUD

MBProgressHUD + Customizations
http://www.bukovinski.com/
MIT License
16.01k stars 3.56k forks source link

Button not appearing in swift version #445

Closed emreavsar closed 6 years ago

emreavsar commented 8 years ago

hey there,

i saw in the demos that there is a button (normally used for cancel actions). I tried to make it visible, but nothing works. I'm on v 1.0.0 of the pods.

        var hud = MBProgressHUD.showHUDAddedTo(v!, animated: true)

        hud.label.text = "Loading"

        hud.button.targetForAction(#selector(MyViewController.cancelLoading(_:)), withSender: self)

        hud.button.setTitle("hello", forState: .Normal)

        hud.button.tintColor = UIColor.blackColor()

The loading label appears (and disappears when I don't set the label.text property), but for the button it does not work.

Any ideas?

Also tried to add a gesture recognizers but did not work. Maybe updating your demos / readme would be also considered as good?

cheers

DannyJi commented 7 years ago

I am also trying to get the button to appear. I am using Swift and Pods. I see the code in the Pod-managed framework.

   var hud = MBProgressHUD.showAdded(to: (self.navigationController?.view)!, animated: true)
    hud.mode = .determinate
    hud.label.text = "Updating Mobile Database"
    hud.detailsLabel.text = "One Moment Please"
    hud.button.setTitle("Cancel", for: .normal)
    hud.button.target(forAction: #selector(cancelDownload), withSender: nil)

The HUD appears but no button. On inspection of the HUD, I can see the button in the hierarchy

- 2 : <UILabel: 0x7fed53a77f00; frame = (0 0; 0 0); text = 'One Moment Please'; opaque = NO; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x61000029f400>>
  - 3 : <MBProgressHUDRoundedButton: 0x7fed53a78180; baseClass = UIButton; frame = (0 0; 0 0); opaque = NO; layer = <CALayer: 0x610000037d00>>

but the frame has zero size.

matej commented 6 years ago

hud.button.targetForAction(#selector(MyViewController.cancelLoading(_:)), withSender: self)

This method returns the target for the specified action instead of setting it. You need to use addTarget:action:forControlEvents:.