0

There are two dynamic labels, one of them tends to be longer than the other. How can I make the shorter label inherit size from the longer one after the longer one shrinks?

I've already seen this post AutoLayout link two UILabels to have the same font size this is not directly my issue, but probably observers could be the solution.

But maybe as for current Swift 2.0 version some other, easier solution has appeared.

Do you have any idea how to constrain font size to be equal to the size of other label after auto-shrinking?

Thanks in advance

Community
  • 1
  • 1
theDC
  • 6,364
  • 10
  • 56
  • 98

1 Answers1

0

You can use this to set font and/or text size:

firstLabel.font = UIFont(name: secondLabel.font!.fontName, size: secondLabel.font!.pointSize)

P.S. pointSize can't be written to- only read.

Charles Truluck
  • 961
  • 1
  • 7
  • 28
  • Unfortunately this is not working, maybe pointSize is read-only? – theDC Oct 12 '15 at 16:27
  • Yes it is, But UIFont can change it. Try `size: 50` just to test. Here's my example of what I'm using: `self.locationLabel.font = UIFont(name: self.locationLabel.font!.fontName, size: self.locationLabel.font!.pointSize / 1.5)` – Charles Truluck Oct 12 '15 at 16:32
  • 1
    But I want this effect to be applied after the second label reached its auto-shrink size – theDC Oct 12 '15 at 16:35
  • I tried printing both sizes after view appeared and they are both 16.0 despite the fact that one of them shrieked due to auto layout – theDC Oct 12 '15 at 16:52
  • Try making it bigger then it actually is in Autolayout, and set Width and Height to static in AutoLayout too. – Charles Truluck Oct 12 '15 at 17:11