swiftuicollectionviewlabelcustomizationviewdidload

how to customize a label when is not in viewdidload?


I have those variables in collectionviewcell file and I want to change label background and cornerradius but that file doesnt have a viewdidload how can I do that . Thanks for helps.


Solution

  • 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
       }
    }