Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing a UIButton by tag value

I am aware that a pushed button can be updated by reference to sender. However I want to access a button from the program body by reference to its tag and then update its label,if that is possible. Suggestions on how to do this (in Swift) would be appreciated.

like image 394
Davy Cotton Avatar asked Feb 12 '15 09:02

Davy Cotton


1 Answers

To get a button inside a view using its tag, you can use the UIView.viewWithTag function.

if let button = self.view.viewWithTag(tag) as? UIButton
{
     button.setTitle("newTitle", forState: UIControlState.Normal)
}
like image 175
rakeshbs Avatar answered Sep 22 '22 02:09

rakeshbs