Coder221
Coder221

Reputation: 1433

Override font in size class programmatically

I have font of an testLabel as Helvetica Neue 12.0 in compact width and compact height class, which I set on the storyboard.

I did this in viewWillAppear

 override func viewWillAppear(_ animated: Bool) {
           testLabel.font = UIFont(name: "HelveticaNeue", size: 18)}

But the font did not change in the simulator. How do I override the size of font programtically?

Upvotes: 4

Views: 431

Answers (1)

Pankil
Pankil

Reputation: 645

Try to change you UILabel font in viewDidLayoutSubviews method.

Objective C:

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    // CHANGE YOUR LABEL FONT
}

Swift:

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    // CHANGE YOUR LABEL FONT
    label.font = UIFont(name: "HelveticaNeue", size: 18)
}

It will work..

Upvotes: 4

Related Questions