How can i set custom attributes on an button that is programmatically created?
I have this code to create an button:
var btn = UIButton(frame: CGRectMake(CGFloat(7 + add), 565, 39, 55))
btn.setTitle(String(Array(shuffledWord)[i...i]), forState: UIControlState.Normal)
btn.addTarget(self, action: "btnPressed:", forControlEvents: UIControlEvents.TouchUpInside)
btn.tag = 7 + add;
I can give some value to .tag but are there more thing like that? Can i create custom attributes to set on the button?
If you need custom properties on a class that doesn't belong to you, subclass it and use the subclass instead.
class MyCoolButton : UIButton {
var myCoolProperty : String = "coolness"
}
And later:
var btn = MyCoolButton( // ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With