I tried to get the title
of a button
in swift like below.
@IBAction func buttonAction(_ sender: Any) {
let buttonTitle = sender.titleForState(.Normal)!
}
but it didn't work,even it doesn't give any hint
when we press .
after the sender.
so what is the correct way of doing this in swift 3.0
Or else if we create an IBOutlet
and then we use its currentTitle
, it works fine like below. Why we cannot get it with sender.
for above
@IBOutlet var thebutton: UIButton!
@IBAction func buttonAction(_ sender: Any) {
let buttonTitle = thebutton.currentTitle!
print(buttonTitle)
}
UIButton
. – Mendelson