I have a subclass of a UILabel that overloads initWithCoder and I was wondering if anyone has any documentation on how the coder is encoded so that I might be able to get information that comes from IB myself.
Thanks.
EDIT
Reason for doing this: I would like the font name given in the xib file. Apple's implementation of initWithCoder disregards the font name given in the file if it's a custom font and when you go to access the label's font, it returns the system font. Therefore I'd like to catch the font name before the original initWithCoder ignores it.
Looking through the documentation, there does not appear to be a way to retrieve all the keys used in an NSKeyedArchiver. One way "around" this is to archive your custom UILabel to an NSData object, write the data object out to a file, and then pop it open in a text editor and see if you can find some of the keys that way.
What information do you need from the UILabel that you can't access through its normal accessors?
If you look at the nib file compiled from the xib file for the interface you wanna decode, you'll be able to make out some of the keys you can use. It's kind of hard to find stuff, but it's better than nothing.
Related
Is it possible to load a font from disk and use it during run-time?
If so, how/where do you store the fonts on the iphone/ipod/ipad for your app to use?
(To be clear, I'm not talking about adding the font as a resource at design-time. I'm asking about a way to allow a user to select a font file during run-time, loading it, and making it available for use.)
You should put them (.ttf, .otf) into your info-plist under UIAppFonts then you can "use" them with setFont: withSize:
You add your font as a resource, add it to your info.plist under Fonts provided by application (UIAppFonts) array, then use it as any embedded one.
Ok, in that case take a look at FontLabel project.
One thing though, looking through it's code - you can only get CGFontRef and with kind of voodoo work with it, no conversion between CGFontRef and UIFont really exists. See this question
When I do translation for web apps, usually I have a script that extracts the strings from the code to a .po file that then I give to the translator, and he has a neat tool that allows him to easily translate all the strings.
On iPhone, is kind of the same thing with the Localizable.strings when it comes to strings in the .m files.
My question is: for translating the UI (the XIB files), my translator will have to have a Mac in order to edit the XIBs or is there a way to extract all the string neatly out of the XIB into a more friendly file format ?
I'm thinking on re-initializing all the XIB elements that have string in viewDidLoad but looks to me like overkill ...
I have seen ppl use ibtool. This might help you.
When an iPhone program has something like a paragraph or a set of instructions that need to be displayed on screen--basically anything that is longer than two sentences, where does it go?
Should it be stored as an NSLocalizedString (is this stored in the info.plist? I tried searching documentation--I'm a beginner and don't quite understand where that goes)?
Should it simply be hard-coded into the UITextView or UILabel that contains it?
Should it be defined as a constant then referenced in the UITextView/UILabel?
Should it be placed in a .txt file then referenced? (http://stackoverflow.com/questions/2506594/where-to-put-text-files-for-iphone-uitextview)
If you are thinking about localizing the text at all, I'd put it into a strings file:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/LoadingResources/Strings/Strings.html
You could also put it into a plist and read the plist file at runtime from the bundle. Generally try to keep the info.plist clean.
I would put such items in a plist file ad read it in.
Is there a tool can change simple .xib to Objective-C code automatically?
I want to I do GUI design in Interface Builder and use the tool convert the .xib file to Objective-C code.
Is it possible?
Sure it's possible, but why not just use the xib?
If you must do this, though, I'd check out nib2objc: https://github.com/akosma/nib2objc
How would I go about italicizing a single word in an NSString which will be displayed in a UILabel? Specifically, I don't want all text to be italicized, just one word.
Thanks!
(Edited) I meant UILabel, not UITextField.
I don't think that what you are asking to do is possible (I'd be happy to be proven wrong). However, this library (https://github.com/facebook/three20/) is a popular way to achieve the same result in a UILabel (not text field) . The library works fairly well, but does have a lot of limitations, especially on edge conditions, and of course, it comes with associated overhead.
I'd encourage you to think about other ways of achieving the same user outcome. Can Placeholder text help? How about hints next to your text field?
Good luck.
A native UILabel does not support NSAttributedString which is what is normally used to display strings with formatting. You could try an output the text your self using Core Text but I would suggest checking out FontLabel or the three-20 project mentioned by #JJ Rohrer
Use NSAttributedString... Find controllers to draw NSAttributedString,since UILabel wont support NSAttributedString
Controller for NSAttributedString