How do I assign this text to label in iPhone SDK
I want to assign below text to UILabel
, but it gave me many errors:
smslbl.text = @"____
|----|-O
/______\
|______|
\______/";
Basically I want to assign the ASCII art of a handgrenade to the label text.
Can you please suggest a correct way of assigning this to a UILabel
?
T开发者_Python百科hanks!
Use control characters to your advantage:
smslbl.text = @"____\n |----|-O\n/______\\\n|______|\n\\______/";
Here I am using the \n
newline character to signify a new line, and I'm escaping the literal \
characters with another \
character.
In Interface Builder, copy-paste the text into the Inspector window for the label under "Text". Set it to use as many lines as you need and size the label appropriately.
Also, make sure you use a fixed-width font!
and set smslbl.numberOfLines = 0
and get the right height for your label with
CGSize size = [sms.lbl.sizeWithFont:<thefont> constrainedToSize:CGSizeMake(max_width, max_height) lineBreakMode:UILineBreakModeCharacterWrap]
精彩评论