How to read and resize UILabel font dynamically?

I have a problem with changing the font size in UILabel dynamically. In my application, I have two tags.

  • The first label size is 90 * 59
  • The second tag size is 59 * 59

Now the problem is that the font size of the first shortcut may change at runtime. I have to change the font size of the second label to fit the font size of the first label.

I used the following method, but it does not work.

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 a shortcut size of only 55. Pls will prompt me to get the current font size (first shortcut) instead of the specific font size in viewdidload.

+4
source share
2 answers

Here's the answer,

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

Note: if I use singe "=" its error. If I use "==", it gives a warning, but also gives the expected result. Actually confused what happens there. Anyone please help me figure this out.

+5
source
  • Font @ "Exo-Light" cannot be set to 55. This is a font problem. Try using sandart @ "Helvetica" to make sure the code works, and then find the font closer to your exo-light (this will behave correctly, of course).

  • Also make sure the labels are correctly connected in xib.

+2
source

All Articles