Frage

I would like to draw cards on a screen that have a small amount of text when they're laid out, more text when they're zoomed in, and ideally animate from one setting to the other like jQuery(...).show('slow');. The beginning state is slightly rotated via an affine transformation; I would like it to rotate and expand to the zoomed-in view.

I have seen the documentation at https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/CoreText_Programming/Operations/Operations.html#//apple_ref/doc/uid/TP40005533-CH4-SW1 , but I want something lower level. I want, in responsive programming fashion, to zoom in and progressively reveal more information according to a triage; so an ID number might come at top when it is zoomed out, then "JS" below it on its own line, expanding to "J Smith" if / when the card is wide enough, and "Jane Smith" if things are zoomed in. Rather than fitting more cards for iPads vs. iPhones, about the same number of cards would fit on one display in either circumstance, but the iPad display would display bigger cards that would include more information when not zoomed in.

Is there any function that can accept a string, a font identifier, and a font size and return how many pixels wide the string is? I know it's usually an error to micromanage what is already low-level in Core Text Programming, but I want a carefully chosen responsive design that is optimized for iPhone small, iPad small, zoomed in, and everything in between that would occur, with progressive disclosure and a triage of information.

War es hilfreich?

Lösung

Yes. For pre-iOS7 (deprecated in iOS7), see NSStrings method (and its other variants)

- (CGSize)sizeWithFont:(UIFont *)font

For iOS7 (and + probably)

- (CGSize)sizeWithAttributes:(NSDictionary *)attrs

Example code:

CGSize drawnSize = [myString sizeWithFont:myFont];
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top