Asked
Active
Viewed 46 times
-3
-
Please post your code rather than pasting image links to it. – πter Feb 17 '21 at 22:05
-
I am sorry for that. I will be careful for next time – Veysel Bozkurt Feb 18 '21 at 11:32
-
Not a problem, it is your interest also, as other people can take your code and work with it – πter Feb 18 '21 at 12:04
-
You're absolutely right – Veysel Bozkurt Feb 18 '21 at 12:29
1 Answers
0
UIView subclasses do not have a viewDidLoad method, instead you use the view's initializer:
class MyCell: UICollectionViewCell {
override init(frame: CGRect) {
super.init(frame: frame)
layoutUI()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
layoutUI()
}
private func layoutUI() {
label.layer.cornerRadius = 5
label.backgroundColor = .blue
}
}

manas sharma
- 463
- 1
- 6
- 8
-
But I using stroyboard and collection view is in storyboard. When I implemented that codes it gave me "'self' used before 'super.init' call" and "'self' used in method call 'layoutUI' before 'super.init' call" – Veysel Bozkurt Feb 18 '21 at 12:01
-
-
well, so sorry the error was fixed but its give me new error at "label.layer.cornerRadius = 5". The error is "Unexpectedly found nil while implicitly unwrapping an Optional value". but my label was defined – Veysel Bozkurt Feb 18 '21 at 14:27
-
Can you please ask this as a different question with the code and provide me with the link? – manas sharma Feb 18 '21 at 14:31
-
-