Sunday, November 8, 2026
HomeiOS Developmentios - How do I apply customized font at customized UIbutton with...

ios – How do I apply customized font at customized UIbutton with swift?

[ad_1]

I’ve added customized font in to my utility and utilized it customized UIButton class like beneath.

import UIKit

class MainButton: UIButton {
    required init?(coder aDecoder: NSCoder) {
        tremendous.init(coder: aDecoder)!
        self.layer.borderColor = UIColor.lightGray.cgColor
        self.layer.borderWidth = 1
        self.layer.cornerRadius = 5
        self.tintColor = .black
        self.titleLabel?.font = UIFont(title: "Myfont", measurement: 14)
    }
}

However it did not work. And I attempted one other manner like beneath.

import UIKit

class MainButton: UIButton {
    required init?(coder aDecoder: NSCoder) {
        tremendous.init(coder: aDecoder)!
        self.layer.borderColor = UIColor.lightGray.cgColor
        self.layer.borderWidth = 1
        self.layer.cornerRadius = 5
        self.tintColor = .black
        self.titleLabel?.font = UIFont(title: "Myfont", measurement: 14)
    }
}

and

@IBOutlet weak var MyBtn: MainButton!
MyBtn.titleLabel?.font = UIFont(title: "Myfont", measurement: 14)

The customized font was utilized at first.
However after I clicked the button, its font modified to system font.
And I attempted like this.

@IBOutlet var MyBtn: MainButton!
MyBtn.titleLabel?.font = UIFont(title: "Myfont", measurement: 14)

However the consequence was similar.
So, how do I apply customized font at customized UIButton?

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments