So far I have only been able to create one iboutlet per button. What i want to achieve is to create one iboutlet for many buttons thus allowing me to write the code for creating the same border width, colour and radius around these buttons only once. Is this possible?
import UIKit
class GameScreenViewController: UIViewController {
@IBOutlet weak var answerTextLabel: UILabel!
@IBOutlet weak var scoreLabel: UILabel!
@IBOutlet weak var questionLabel: UILabel!
@IBOutlet weak var numberBtn: UIButton! //this iboutlet is what i would like to be able to connect to multiple number buttons in my app.
}
2
Answers
you can use
IBoutlet Collection
!You can connect several same types of objects after declaring as IBoutlet Collection.
And if you want to run the same code, you can use the for statement.
The above solution recommended is indeed correct. There is an option for connecting collection of IBOutlets. But you need to make sure all the IBOutlet it connected to the collection are of the same type. For example collection of UIButtons only.
You connect using New Referencing Outlet Collection instead of New Referencing Outlet