Young Deezie Young Deezie - 7 months ago 18
Swift Question

Swift: Creating a function to edit UILabel settings

I'm trying to use a function so I can efficiently change the settings of many UILabels at once. I'm trying to treat the label as a variable to show what I want to do. How could I achieve this?

func colorBlock(label: UILabel) {
self.label.backgroundColor = UIColor(red: 0.0, green: 0.0, blue: 1.0, alpha: 0.75)
}

Avt Avt
Answer

Remove self:

func colorBlock(label: UILabel) {
     label.backgroundColor = UIColor(red: 0.0, green: 0.0, blue: 1.0, alpha: 0.75)
}

because label in this code is a function parameter and self.label is a property of a class this function belongs to.