views:

999

answers:

5

Does anyone have any examples or resources where i might find information on scrolling text which is too long to display in a button control? I'm thinking something along these lines.

  • Display as much text will fit within the current rect with a '...' at the end to signify overflow.
  • Pause for say 1 second then slowly scroll the text to the right edge displaying the right part of the string.
  • Display as much text will fit within the current rect with a '...' at the beginning to signify overflow.
  • Start the whole thing over in reverse.

Is there an easy way to do this using the "core" or built in "animation" frameworks on a certain mobile device?

[edit] Iwanted to add some more details as i think people are more focused on wether or not what i'm trying to accomplish is appropriate. The button is for the answers on a trivia game. It does not perform any speciffic UI function but is for displaying the answer. Apple themselves is doing this in their iQuiz trivia game on the iPod Nano and i think its a pretty elegant solution to answers that are longer than the width of my button.

In case its the '...' that is the difficult part of this. Lets say i removed this requirement. Could i have the label for the button be full sized but clipped to the client rect of the button and use some animation methods to scroll it within the clipping rect? This would give me almost the same effect minus the ellipses.

A: 

Pretty sure you can't do that using the standard API, certainly not with UILineBreakMode. In addition, the style guide says that an ellipsis indicates that the button when pressed will ask you for more information -for example Open File... will ask for the name of a file. Your proposed use of ellipsis violates this guideline.

You'd need some custom logic to implement the behaviour you describe, but I don't think it's the way to go anyway.

Airsource Ltd
+1  A: 

Without wishing to be obtuse, maybe you should rethink your problem. A button should have a clear and predictable function. It's not a place to store and display text. Perhaps you could have a description show on screen with a nice standard button below?

cam8001
A: 

This is not a very good UI practice, but if you still want to do it, your best bet is to do so via a clickable div styled to look like a button.

Set the width of the div to an explicit value, and its overflow to hidden, then use a script executing on an interval to adjust the scrollLeft property of this div.

levik
+1  A: 
Mecki
My UI does NOT use any of apple's stock built in UI elements and i would like to keep it that way. While i appreciate your table suggestion it would not fit with my theme. Please see http://driph.com/words/2008/08/game-trivia-catechism-iphone-teaser/ to get an idea of why i am trying to do this.
Lounges
Thanks for the code samples. I actually picked up the pragmatic programmers core animation book and got a sample very similar running in core animation and have decided not to go with it as it did not look good with 4 buttons scrolling text.It was a neat idea to try though.
Lounges
+1  A: 

Here's an idea: instead of ellipses (...), use a gradient on each side, so the extra text fades away into the background color. Then you could do this with three CALayers: one for the text and two for fade effect.

The fade masks would just be rectangles with a gradient that goes from transparent to the background color. They should be positioned above the text layer. The text would be drawn on the text layer, and then you just animate it sliding back and forth in the manner you describe. You can create a CGPath object describing the path and add it to a CAKeyframeAnimation object which you add to the text layer.

As for whether you think this is "easy" depends on how well you know Core Animation, but I think once you learn the API you'll find this isn't too bad and would be worth the trouble.

benzado