Reputation: 713
I have some experience in SKSpriteKit
and I am writing code in UIViewController using UIKit library. And I wonder if I could access existing propteries such as ones from UILabel
, UITextField
, UIView
, and so on. In Swift, nodes can be named and called by their names using childWithName(name: String)
, so is there any way to do this in UIKit. ? I thought doing this would be much more convenienet and my writing would go smooth. I started programming in UIKit so I do not know much about it, so I appreciate if you teach me abou this!
Thankyou
Upvotes: 0
Views: 30
Reputation: 274835
You can't give "names" to UIView
s as far as I'm concerned. However, there's something similar.
You can set a view's tag
by doing:
someView.tag = 1
Then, assuming that superView
is the super view of someView
, you can do this to get someView
:
superView.viewWithTag(1)
It's not as descriptive as name
, but you can use named constants to make it clearer:
let scoreLabelTag = 1
superView.viewWithTag(scoreLabelTag)
Upvotes: 1