Multiple UILabels to display decorated XML markup - iphone

I have a block of content (stored in XML) that I want to put in a UIScrollView. Certain parts of this text will be formatted with different fonts, sizes, and colors. Altogether, it mostly reads as a paragraph with word wrapping.
I've built my NSXMLParser code, and I have separated all the data. I'm ready to apply my decorations and add these elements as UILabels.
However, I'm looking for a solution to ease the inherent difficulties of string height/width calculations and all of that arithmetic to make these UILabels line up with word wrapping nicely. [keeping track of your last X and Y coordinates, knowing when to insert manual line breaks, how to best vertically display a line that has 2 different sized fonts]
The XML markup can easily be converted to HTML, and thus UIWebView, but I hear that is slower to load.
Is the UIWebView going to be the best class for this? I wish there were one that did all of this with UILabels so that I can use these elements for touch events. (I assume that I cannot use an HTML element to trigger a touch event.)

You should probably a UIWebView. You can use an HTML anchor for touchable elements. The delegate will give you the option of doing something other than loading a web-page when the user touches the element. You can use a made-up URL format to uniquely identify each element.
Aside from that, you may want to use a custom control that draws all the text, rather than a series of UILabels. The UILabels will probably make it difficult to do line wrapping.

Related

Word Styles to get two elements to share same background/border

Within MS Word 2013 I am trying to create a text element plus a list underneath it, all wrapped inside a coloured border with background shading (see image). The attached image shows the text in plain form.
I would like to place a blue border around both the title and the list. I can achieve this by placing both objects within a 1x1 table and applying colouring rules to the cell, but semantically this seems bad (I'm from an HTML development background where it is very wrong!)
When I edit a Style rule to create the border/background, it works well until I create the list, then it goes badly wrong. Is it possible to achieve the output of the table cell approach by only using a style rule and no table?
After a day of experimentation, the closest I can get is by doing the following:
Create a style rule called Tips Heading based on Normal, then set it to be Bold with a blue background.
Create another style rule called Tips List based on List Paragraph, and set it to have a blue background.
Unfortunately the List cannot be indented because the background colour also indents. The border is also affected in this manner, so I ignored the border and indentation. It works really well and is semantically well structured.

How to center align, ignoring certain characters?

Look at this UILabel. It's center-aligned:
Now look at this UILabel. Although it is technically center-aligned, it really doesn't look that way:
The reason why it looks like this is because the center-alignment considers the degree symbol a third character, thus bumping the other two off to the left a bit. My question is: is there any way to ignore certain characters whilst center-aligning a label?
Interesting question. The only solution that comes to mind for me is to pad the text string with spaces on the front to cancel out the ignored characters on the back.
That is, to center #"60d" as if it were #"60", set the text to #" 60d". This works well with a fixed width font, but otherwise is only a rough approximation.
If you like this idea and want to get fancy with it, then you can use NSStrings method
– stringByPaddingToLength:withString:startingAtIndex:
perhaps in conjunction with – rangeOfCharacterFromSet: or some such method to determine how many spaces to pad with.
You could of course measure the text string(s) and compute your own positioning, rather than using text alignment in a larger field.
Assuming you don't want to do that, another idea that comes to mind is to display the string “°60°” with the first character styled with a color of opacity 0 and no shadow.
I don't do iOS development so I don't know how practical these are.

Formatted Text in UIScrollview

What i Need to do for our project is to Display several UIScrollViews in a View and weithin the scrollView a Headline and a Short Text.
I Know how to add a Label to the UIscrollview, but how Gould i handle the Case that the Headline-Label is too Long and wraps to a Second Line.
You can determine the space needed for the headline text by calling -[NSString sizeWithFont:] or one of its variants. Then size and position the labels dynamically in your code (and set their numberOfLines property to 0).
Alternatives:
Use a UIWebView to display formatted text (HTML).
Use Core Graphics to draw the text directly into the view (e.g. [NSString drawAtPoint:withFont:]).
Use Core Text to format and draw the text (quite complicated).

UILabel and superscript

I have two strings:
a variable length piece of text
another string with numbers that
point to a reference
In my view, the first piece of text is displayed in a UILabel, I adjust the size of the label to accomodate the size of the text. This means I cannot just place another UILabel on the screen, at least not without repositioning it...somehow.
I need to be able to put the second piece of text so it appears to be at the end of the sentence - and superscripted
I really have no idea how to achieve this!
My rather dodgy solution was to enter unicode characters for the superscripted numbers.
Not a great solution but it worked.
The simplest way would be to use two different UILabels. A better solution might be to draw both strings using -drawInRect:withFont: in a custom view's -drawRect: method.

Spacing between characters on the iPhone

I have a label and I wish to increase the spacing between characters.
I tried adding a space between each character, but this was too much
Perhaps there is a font with large spacing between the letters?
If all else fails, I am considering putting each character (only a size character code), into its own textbox.
Any ideas on how to achieve this?
There is a way to insert a half space, but I don't recall the exact command (option-spacebar?). Wikipedia has a complete list of spaces you can use.
Another approach would be a UIWebView with the letter-spacing CSS attribute set.
You're better off creating a custom view and using your drawRect routine to draw the text manually. You can use CFAttributedString to hold your text along with kerning information.
Update: sounds like you can't actually use CFAttributedString to draw text on the iPhone. You can still use your drawRect to draw the customized text, but it will take some more work to actually get your custom kerning to work.