Reputation: 25969
Any ideas on how to get the functionality of an attributed string on an iPhone.
Specifically, I am writing out chemical compounds and want to properly display subscripts: for example:
H2O (the 2 should be a subscript)
Thanks for any suggestions
Upvotes: 1
Views: 1260
Reputation: 2703
Just posting this to help others trying to make the scientific notation work. Works for 3.2 and higher (maybe lower, just give it a shot ;))
// Property to show
NSString *formula = cellData.formula;
// Setup font
UIFont *font = [UIFont fontWithName:@"Dax-Bold" size:5];
// Draw property
UIGraphicsPushContext(context);
[formula drawAtPoint:CGPointMake(cellData.rect.origin.x + 2, cellData.rect.origin.y + 15) withFont:font];
UIGraphicsPopContext();
The drawAtPoint:
uses the current context so make sure you use this method in you drawRect: method.
I had to wrap the drawAtPoint:
method with two UIGraphics methods to make sure my text got rendered in a multi thread application.
Make sure that your font supports the unicode characters. If it doesn't the default font will be used. You can add missing font glyphs with a tool called FontLab.
Upvotes: 0
Reputation: 32336
You may find it more convenient to use the Unicode characters set up for subscripts:
SUBSCRIPT TWO is U+2082: H₂0
Upvotes: 6
Reputation: 85532
You can use a UIWebView and HTML, or draw it yourself using the NSString + UIKit additions, or CoreGraphics.
Upvotes: 1