How to access an Interface Builder UILabel with code?

121 Views Asked by At

There's a UILabel in Interface Builder without a custom class or tag. I need to programmatically change the y coordinate of this UILabel. I know I can reference the UILabel by setting the tag and using viewWithTag. But how do I do it with IBOutlet? Can I set the custom class in IB and then somehow reference the custom class and assign it to an IBOutlet var?

1

There are 1 best solutions below

3
jrturton On

You don't need the label to have a custom class for this. Add an outlet to the owning class (typically, the view controller):

@IBOutlet var label: UILabel

Then in the storyboard, drag from the outlet in the connections inspector over to the label in interface builder.