Custom Label and OOP

I added a photo as an example of "how we can initialize and assign properties" so I wonder If can do the same thing for Labels to assign their value by myself?
No description
No description
4 Replies
grimlessbbs
grimlessbbs14mo ago
Can you rephrase this question, please? I don't understand what you are trying to accomplish
_lefebvre
_lefebvre14mo ago
in first photo properties declared and initializied by init method. In the second one I assign some attributes to label so; as in the first photo can ı do something like var customLabel : UILabel and then initialite it with directly init() methos like in the musician class
xPsycHoWasPx
xPsycHoWasPx14mo ago
UIKit in 2023 ?
grimlessbbs
grimlessbbs14mo ago
public extension UILabel {
convenience init(frame: CGRect, text: String?, font: ...) {
self.init(frame: frame)
self.text = text
self.font = font
...
}
}
public extension UILabel {
convenience init(frame: CGRect, text: String?, font: ...) {
self.init(frame: frame)
self.text = text
self.font = font
...
}
}
let myLabel = UILabel(frame: ..., text: "fooo", font: UIFont.preferredFont(fontTextStyle: .headline), ...)
let myLabel = UILabel(frame: ..., text: "fooo", font: UIFont.preferredFont(fontTextStyle: .headline), ...)
Yes? No?
Want results from more Discord servers?
Add your server