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.
Related
Let's say I have a UITableView cell which, by definition, has a textLabel associated with it. This textLabel surely has a frame which reaches to the end of the UITableViewCell, by default. Let's say that my textLabels on all my cells have different amounts of text. Some have one letter, some have three words.
I want to determine the pixel location of the last letter (or just the end of) a UITableViewCell's textLabel. Is this possible? I'm trying to draw a strike through line through the textLabel's text.
NSString has a method that returns the size given a UIFont, that size, plus the origin of the label should help your find that point you are looking for.
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:
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.
I have two UILabels. that I want to overlap one atop the other. Call the labels "under" and "over".
over: A C E G
under: B D F
UILabel "over" will have its text drawn in red. "under" will be in blue. The visual effect will be alternating colors between successive letters.
What are the controls available to me to exactly align the text in each label to pull this off?
Cheers,
Doug
I agree with fbrereton. This seems a very hard way to achieve the goal. Check out the NSString UIKit Additions to learn how to draw your own strings and lay the characters out yourself in your own custom -drawRect:. You'll have far greater control, and the code should not be that complex. iPhone doesn't have very good layout support (nothing like Mac offers), but for something this simple, it shouldn't be too bad.
You have to make sure the font you are using is a monospace font, otherwise the characters will not line up exactly as you would hope with just a space between them. (I believe there is a typewrite font available in the iPhone OS that is monospace; YMMV.) Also you will have to prefix underLabel with a space for the code below to work.
To map one UILabel on top of another, try:
overLabel.opaque = NO; // so you can see what is under overLabel
overLabel.textColor = [UIColor redColor];
overLabel.backgroundColor = [UIColor clearColor];
underLabel.frame = overLabel.frame;
underLabel.textColor = [UIColor blueColor];
Note in the above code underLabel takes on overLabel's frame because the latter's frame is wider; if it were the other way around overLabel would get clipped.
All that being said I'd wager there is a better way to skin this particular cat. This solution feels very "round peg, square hole" to me.
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.