DBLCDTempBlack only for some letters in UILabel - objective-c

I am uising this code for marquee effect. i want digital clock like font so i gave font as
UIFont *lcdFont = [UIFont fontWithName:#"DBLCDTempBlack" size:60.0];
self.font = lcdFont ;
But i am getting this font only for some random characters.I am using only uppercase letters. I want i for all the characters in UILabel.
Why is it happening so.

It's nothing wrong with your code -- that font only has certain characters in it. (Why? Who knows.) For those it's missing, the OS automatically falls back to another font.
If you want to draw LCD-looking text using a broader character set, you'll need to find such a font elsewhere and bundle it in your app.

Related

How do I get the current font/font size at cursor in NSTextView?

Clarification: First, cursor = the insertion point cursor, not the mouse cursor.
Ok, I would like to return the font / font size / font color wherever the cursor is in the NSTextView. I tried using attribute:atIndex:effectiveRange:, but I failed because I got my variables all mixed up. I think it is what I need. Some example code would just be appreciated, returning the font. I think it will work the same for font size/color, I'll just have to substitute NSFontAttributeName for something else, right? Thanks in advance!
NSFont *font = [textView.textStorage attribute:NSFontAttributeName atIndex:textView.selectedRange.location effectiveRange:nil];
Should work for all getting the name.
What have you tried?
NSTextView has a method selectedRanges which returns the current selection(s) - just one of zero-length if there is just an insertion point.
NSTextView also has a property textStorage which returns back the instance of NSTextStorage which holds the text. An NSTextStorage inherits from NSMutableAttributedString, which inherits from NSAttributedString, and that has methods to obtain the attributes of the text.
Combined those two and you have your answer.
HTH

Change font color in NSTableHeader

How can I change font color in header of NSTableView?
In Xcode Interface Builder - any color modifications in Font Panel of Table Column properties are ignored / discarded.
Also I can not find a proper information my problem in Apple documentation.
Does anyone know is it possible ?
For each of the NSTableColumns in the [NSTableView tableColumns], do:
[[yourColumn headerCell] setAttributedStringValue:yourNSAttributedString].
The font color will be keyed to NSForegroundColorAttributeName in your string attribute dictionary.

PDF creation and text formatting

Question about text formatting when creating a PDF programmatically on the iPhone.
I have a formatted NSString with Tabs (\t) in it. On the debugging output it looks perfect and fine, but when this strings is used to generate a PDF, the Tabs are gone and replaced by a single space.. Any idea?
( Tried a font like Courier, no luck, also the page boundary is big enough, there is more then enough room to display the text)
This is the code I use to make the PDF:
- (void)drawStuffInContext:(CGContextRef)ctx {
UIFont *font = [UIFont fontWithName:#"Arial" size:10];
CGRect textRect = CGRectInset(kPDFPageBounds, 36, 36);
[textHolder drawInRect:textRect withFont:font];
}
You're not very clear in describing what exactly you're doing.
But the first thing I would try is this:
Replace your tabs with spaces yourself -- use as many spaces for each tab as make you happy.
Then convert this new string/text to PDF.

How do I calculate the exact height of text using UIKit?

I'm using -[NSString sizeWithFont] to get the text height. The character 't' is clearly taller than 'm', but -sizeWithFont returns the same height for both these strings. Here's the code:
UIFont* myFont = [UIFont fontWithName:#"Helvetica" size:1000.0];
NSString* myStr = #"m";
CGSize mySize = [myStr sizeWithFont:myFont];
With 'm' as shown, it returns {834, 1151}. With myStr = #"t" instead, it's {278, 1151}. The smaller width shows up as expected, but not the height.
Does some other function wrap the text tightly? I'm ideally looking for something equivalent to Android's Paint.getTextBounds().
The information you get back from this method is basically the line height for the font (i.e., it's the ascent plus the descent for the font you've chosen). It's not based on individual characters, it's based on specific font metrics. You can get most of the information about a font's metrics from the UIFont class (e.g., the method -ascender gives you the height of the ascender for the font). Mostly, you will be dealing with the total amount of vertical space needed to draw the glyphs with the heights ascenders and the lowest descenders for that font. There is no way to get information about individual glyphs from UIFont. If you need this information, you'll have to look at the CoreText framework, which gives you a lot more flexibility in how you draw and arrange glyphs but is far, far more complicated to use.
For more information on dealing with text in your app, please se the Drawing and Managing Text section of the Text, Web, and Editing Programming Guide. It is also a good launching point for most of the frameworks and classes you'll need to deal with whether you go the UIKit or the CoreText route.
Hmmm... I assume you're only going to be working with individual characters then. sizeWithFont, as noted above, returns the height of the largest character of that font as the text field is going to be that height no matter what you do. You would be able to get the LARGEST height values (UIFont's CGFloat capHeight) however it looks like you're going to be working with all kinds of text
I would take a look at the CoreText framework. Start here and read away. Inevitably you're going to end up with something along the lines of this:
CGFloat GetLineHeightForFont(CTFontRef iFont)
{
CGFloat lineHeight = 0.0;
check(iFont != NULL);
lineHeight += CTFontGetLeading(iFont);
return lineHeight;
}

UILabel and right to left text

I have a collection of NSString objects that contain arabic text. However, when I try to display any of them using a UILabel, the text shows left-to-right instead of right-to-left (NSLog shows the strings properly)
I am thinking about a work-around, applying a transform to the UILabel to make a y-axis symmetry, but how can I detect if a NSString contains a RTL string?
Try prepending the unicode character 0x200F to the beginning of each string. This character is an invisible marker character that indicates text directionality.
Have you tried setting your region to Arabic? I would have thought this type of thing would be handled automatically.