3

A small explanation about what I have:

I have a UIPickerView with more than one component (column), and all the components are filled with INTEGER_MAX rows, in order to give that "infinite loop" aspect. The content of each component comes from the NSArray of strings for that specific component. The strings (words) have different sizes, and some were being truncated (for example, "Imagination" became "Imaginat...", while "Smart" stays the same). In every row in every component, I'm using a UILabel to show the text, and I'm using

tLabel.textAlignment = NSTextAlignmentCenter;
tView.adjustsFontSizeToFitWidth = YES;

to make sure that the text fits and is aligned.

A small explanation about what I need:

I need to make all the labels (INTEGER_MAX * nr_of_components) have the same textsize. However, until the picker is populated with the labels auto-resizing the text, I can't tell which one is the smallest font.size in there.

A small explanation about what I was thinking and haven't been able to achieve:

I considered loading the picker as it was explained before, and then scan the first [arrayX count] rows to find the minimum needed fontsize for that component, then compare it against the other components, until the 'absolute' minimum fontsize needed was discovered. After that, it would be required to access ALL the labels on ALL the components and change the font.size to the one indicated as the smallest one needed.

This should be done dynamically because it won't be known if the app is being ran on an iPhone, iPod or iPad.

Well, any help is quite welcome. Thanks in advance!

1 Answers1

1

If I understood your question correctly, you may want to take a look at this answer.

The strategy is basically to truncate (ellipsis) instead of font shrinking.


Edit (based on comment)

I would strongly advise against setting all text to the minimum font. Lets say you have elements as such:

  • Pear
  • Peach

ok, so far these will fit your label perfectly, with a good font size. Now you add a longer item:

  • Pear
  • Peach
  • Strawberry
  • Pineapple

and now all your items are a little bit smaller, but thats still readable, so it's acceptable. And then a huge item appears, such as:

  • Pear
  • Peach
  • Strawberry
  • Pineapple
  • SomeKindOfExoticFruitThatHasAnIncredibleLongName

which would make all items inside your picker become incredibly small, and difficult to read.

But if you still want to go down that road, I suggest that you take a look at font sizing from text. This question may also help.

Community
  • 1
  • 1
Joel
  • 7,401
  • 4
  • 52
  • 58
  • Thank you for your reply, but I already have that behaviour by default on the labels, as I explained before. However, what I want is to have them all at the same size, and not truncating (elipsing). The idea I have is to change all the labels, but it+s not being easy. – Flávio Marques Aug 28 '13 at 10:47