Veera Raj
Veera Raj

Reputation: 1562

How to Read and Chage Font Size of an UILabel Dynamically?

I have a problem at changing the font size in an UILabel dynamically. In my app, I have two labels.

  1. The first label's size is 90*59
  2. The second label's size is 59*59

Now the problem is, The first label's font size may vary during run time. I have to change the second label's font size according to the first label's font size.

I have used the following method but it doesn't works.

    CGFloat secondLabelsize = firstLabel.font.pointSize;
    [seconLabel setFont: [UIFont fontWithName: @"Exo-Light" size:secondLabelsize]];

    viewDidLod
    {
    [hr_lbl setFont: [UIFont fontWithName: @"Exo-Light" size:55]];
    }

Every time i have got label size as 55 only. Pls suggest me a to get current font size(first label) instead of defined font size at viewdidload.

Upvotes: 4

Views: 320

Answers (2)

Veera Raj
Veera Raj

Reputation: 1562

Here is the answer,

label2.frame.size.width == label1.frame.size.width;

Note : if i use singe "=" its an error. If i use "==" it gives a warning but gives expected output too. Really confused what's happening there. Any one please guide me to understand this.

Upvotes: 5

John Smith
John Smith

Reputation: 2022

  1. The @"Exo-Light" font is not able to be set to 55. It'a a font issue. Try using sandart @"Helvetica" to make sure the code works, then find a font closer to your exo-light (that will behave correctly, of course).

  2. Also make sure the labels are properly hooked up in xib.

Upvotes: 2

Related Questions