Looks there is issue with fonts support when porting from Cocos2D IOS project using Apportable. If font extensions is written with capital letters like "cartoon.TTF" and then labels initialized with "cartoon.TTF" text will not be visible or will be used standard font instead of defined.
Would be nice to have font support no meter of letters case in apportable
To fix it you should rename font extension to lower case letters like "cartoon.ttf" and change labels property to "cartoon.ttf".
Related
I often use font data (.ttf or .otf) in Swift to change font of UILabel. But sometimes I use only show numbers in UILabel and think which is better using font data or image data of each numbers like "1_image.png", "2_image.png", "3_image.png"...
Of course if I want to show many characters like articles and messages I should import font file in project. But I'm not sure which is better to show only numbers in the specific situation like showing user game ranking and scores.
I think it is almost always better to use a font -- as long as you are allowed to distribute it. Some of the advantages of fonts are:
They scale
No need to bother about pixel resolutions
More options to align them (like baseline etc.)
Better support for accessibility (like adjusting the contrast etc.)
I'm going to draw the text of bold/italic style in iOS.
I know it's possible to use the various font faces such as xxx-bold, xxx-italic or .ttc font package file.
But I'd like to use a regular font file.
Is this possible? how to?
In TextEdit of OS X, it's impossible to select bold/italic style without the appropriate fonts.
But in Microsoft Office for Mac, it's possible with a regular font file.
I am writing an app that requires labels w/ musical accidental symbols, called sharp and flat (♯ and ♭, respectively). Specifically, I need a label that says c♯. It is irrelevant to the question what these two symbols mean within a musical context. My app's main font is Open Sans. However, because Open Sans doesn't specify a character for the sharp and flat symbols, it uses a generic sharp and flat symbol that I find unattractive. However, I know that Helvetica Neue (or the iOS system font) has some well made symbols for sharp and flat, so I decided to change the label's text to an attributed string so I could make the c Open Sans, and the ♯ Helvetica Neue (both size 24). I did this through the interface builder. Even though everything looks exactly the way I want in the storyboard, when I launch it in the iOS Simulator, the labels with attributed strings are significantly shrunken from the other labels. I should note that the label has 3 AutoLayout constraints, though these contrasts are positionally related only, not size related.
Things I have tried (unsuccessfuly):
Using only one font
Doubling the font size (was too big)
Removing autolayout constraints
I would greatly appreciate it if someone could explain how to correctly create these labels. I am happy to provide any more information that is needed.
Thank you
I discovered that the problem is that NSAttributedString does not (yet) support custom fonts through Interface builder. It looks like I will have to subclass. This question essentially boils down to be the same as this one: Attributed string with custom fonts in storyboard does not load correctly
I usually have 4 files per font. For instance
menu-ipadhd.fnt
menu-ipadhd.png
menu.fnt
menu.png
Question is, should I localize all 4 files or .fnt localization is enough? Can Cocos2D find png file from corresponding .lproj? What is the proper way to localize bitmap fonts?
Whether cocos2d finds files according to language is easy to test, put two different files one in en.lproj and the other in some other language folder, then change the device's or simulators language and see whether it picks the correct one for each language.
If you are meaning to localize the text (strings displayed with a bitmap font) you really just have to localize the strings and make sure that for all supported languages all language-specific characters (äéøß and such) are included in the bitmap font's image. At least all of those actually used by your localized strings.
If you are localizing to a completely different character set, for example from english to cyrillic, asian or arabic languages, you need to provide different bitmap fonts altogether, ie both fnt and png files and load them according to the language. This is next to localizing the text itself.
The reason is that these non-latin character sets contain hundreds if not thousands of different characters, so including them in a single bitmap font is not desirable and may not even be possible to fit them all in 4096x4096 (or less) texture space.
Some cocos2d version's bitmap font class limits the number of characters in a bitmap font to 2048 - this may apply only to v1.x I haven't checked if that limitation still exists in 2.x in general, I just can't locate it in 2.1 anymore. For character sets that exceed this number of characters you will have to increase that number in the header of CCBMFontLabel - if available.
Be careful though with large bitmap fonts as the storage per letter can add up quite significantly, an entire font can use several megabytes - not counting the texture itself!
I am wondering if it is possible to add small icons, that are available as png files, during launch time to a custom font I use in my app? The code should work on iOS5 and above. This would have several use cases. For example you could add labels with icons without using an image view and a label and layouting the stuff based on the text. I know that I have read somewhere, that apple uses this technique on their own apps, but I don't know if they add the icons on launch time or already in the design process into the font.
Any help would be appreciated.
I have simulated this by using a custom view that has a string and font property as well as one or more images. Create a mapping between special char values and images. In drawrect use the uikit category on NSString that lets you draw chars or strings. When u get to your special char you skip it and draw the image. Those draw methods return the size of the string/char so you can tell how much to move as you draw.
You can see this technique used on github, look for the CreditCard ObjectiveC. It's used to draw placeholders or chars in the PlaceHolder class
I think it is not possible to add png to font in device. Font file use vector graphics to represent every glyph. You can convert font file to SVG. But PNG is not vector graphics.
I use icon font in some of my projects. I have create a project to use icon font easily. https://github.com/JohnWong/IconFont. Icon font is always used in UILabel by setting text. But I think creating a UIImage from font is more flexible. UIImage can be used in Buttons, TabBar Items, Bar Button Items and so on. This is why I create this project. The README of this project is written in Chinese. But the demo project will show everything clearly.