tags:

views:

965

answers:

3

I am trying to get text to resize automatically to fit a UITextField. I have the adjust to fit value set in interface builder but what happens when I build and go is the text goes from the default size, to the minimum size and never increases in size when less text is in the box.

I want to get text to work the way it does in apples iPhone calculator. How do I do this?

+2  A: 

Text fields will never make text bigger. They will only reduce it in size from the default to the minimum size.

So, you need to change your defalt text size to be bigger.

Keep in mind that you're working with both a height and a width. Unless you have a square text field, no amount of adjustments will fill the field in both directions.

August
+1  A: 

I understand that. My default size is 42 points. My minimum size is 24 points. When I start typing the text is 42 points. When I fill the text field and then hit the next number to enter the text reduces to a much smaller size and only takes up about 1/3 of the text field. I think the text is actually smaller then minimum size. if I clear the text field and start over the text stays at the small size.

I want the text to grow and shrink dynamically based on the amount of text in the text field with an upper bound of the default (42) and a lower bound of the minimum (24).

Unless I am missing something, this interface builder feature does not work as it is supposed to.

Has anyone got this to work? Is there additional code that needs to be implemented?

Steve
That sounds like a bug. You may want to file one at http://bugreport.apple.com/
Daniel Dickison
A: 

I'm seeing the same problem, both problems actually. The first is that the resized font size is smaller than what I specified as the "Min Size" in IB. The other is that it will not reset to the larger size when text is removed. I haven't figured anything out yet. Any luck with this?

EDIT: Actually, I just figured out that if you use a UILabel instead of a UITextField, then it works as we would like it to. Give it a try.

Brice