Home > Blockchain >  How to call UILabel class to apply it to label in Swift?
How to call UILabel class to apply it to label in Swift?

Time:09-01

I am trying to create a class contain UILabel properties such as font name, size and color so i made something like this:

extension UILabel{
    
    func DesigenLabel(){
        
        let label = UILabel()
        label.font = UIFont(name: "mohammad-bold-art-1", size: 20)
        
       
    }
}

and I call the class as:

self.lbEntranceMessage.DesigenLabel()

Nothing change with the label, the font is the same. I have no idea how to sort it out.

Thanks

CodePudding user response:

You are creating a new instance of the UILabel, setting its font and throwing it away.

You would need to set the font on self. meaning the UILabel this function is called upon e.g.:

extension UILabel{
    func desginLabel(){
        self.font = UIFont(name: "mohammad-bold-art-1", size: 20)
    }
}
  • Related