iPhone's UIStringDrawing for multiple lines - iphone

I want to draw a long NSString with UIStringDrawing and linebreakmode "word wrap". The problem is, that it only draws one line also with this linebreakmode parameter. Do i have to calculate this manually and split the string into an array to draw each line?
I don't want to use UILabel with numberOfLines stuff. I put emphasis on performance in the User-Interface (so I would pre-calculate that stuff).
Thank you!

The answer is really simple
NSString:drawInRect:withFont:

Related

Line Spacing in xcode/swift Label and TextView

My question is related to solving a problem and also to improve my understanding of swift.
I have a UILabel and a TextView. I have the same size font in both. However, in the TextView I am using attributed strings. The fonts appear the same but the line spacing is greater in the label. My problem is I cannot find a way to change the line spacing in the Label other than switching to Attributed String for the Label or for that matter even determining what the present spacing is.
Q1: Is there no other way to control the label spacing other than Attributed Strings?
Q2: Because of issues like this, should I be thinking that Attributed Strings might be a "best practice" regardless -- to give more control?
You can set linespacing in Label Attribute inspector.
See screenshot.

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.

iPhone: UILabel text does not fit the way i want

I have a UILabel with some text on it, what I want is if the text with the given font does not fit to the label, I want it to be first linebreaked to a second line, and if still does not fit then it should automatically adjust those 2 lines to a smaller font.
I experienced with the IB changing the settings of linebreaks and number of rows, but couldn't get what I want.
Any recommendadtions?
To my knowledge UILabel does not support auto adjusting the font when there is more than one line.
The only way I know of it to iteratively calculate a fitting font size and then to set the appropriate font manually.
Maybe the sizeWithFont: method is a solution for you:
– sizeWithFont:forWidth:lineBreakMode:
This calculates the width / height of a NSString with the appropriate font / settings

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.