UILabel and superscript - iphone

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.

Related

NSString or UILabel with a backslash through a letter

Is it possible to make certain letters in a word have a slash through it? I have a tableview with a list of words, and I want to draw a slash through "silent letters"
What would be the best way to approach creating UILabel's to look like this?
I guess the best would be to not use UILabel at all.
Create your own UIView subclass, override drawRect and draw the text. Then draw the lines over letters. If you have the font and the text, calculating the position for the line is pretty trivial.

Devide text to UITextViews

I have long text and 2 textViews.
I need to insert this text to 2 textViews(they have no scrolling).
It's like book pages(first page is a one textView, second page is a another textView).
So, question is: how to determine which text length I need insert to first textView?
You can set the complete text to the first textView, calculate the visible text range and set the remaining text to the second textView. An alternative is to manually calculate the range of the text that will be visible in the first textView, however it requires ugly recursion with sizeWithFont that i can't believe is so fast, i'd follow the first way.
See this answer to learn how to get the visible text range.
First figure out length of each line, font, and how many lines you can fill into the each textview. Use following to do this
CGFloat stringWidth = [text sizeWithFont:[UIFont fontWithName:your_textview_font_name size:your_textview_font_size]].width;
Then use substrings operation.
Shouldn't be difficult to do this!

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.

UITableView cell text is cut off

I am having a problem with the UITableview cell cutting off strings whose characters are more than 12 chars. Any ideas why this would occur? I have not made a custom cell at all. I cannot find any solution to this problem through a Google search. Any ideas?
You should be able to set the label properties to re-size the font based on the label's contents using adjustsFontSizeToFitWidth. This will essentially decrease the font size to make the text fit all on one line.
Your cell likely contains a label, which in turn is set to given bounds. What you need to do is ensure that your label is the same size as your longest string, or bigger than it.

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.