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.
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 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’m new in iOS and trying to make simple app with hierarchy of viewcontrollers. In the last one I wanna display scrollable image (which can also be zoomed at least x1,5), containing some small black and white picture and a piece of text. Initially I planned to make vector image, convert it to .jpg and use UIScrollView for displaying. But I found out that .jpg ( approx. 150 KB) didn’t provide a good quality for displaying text. As I have to use a lot of images I don’t want to increase image size. What is worse I also want it look good on retina display.
Can you recommend a way how to display image, containing text, with enough quality?
I mean that I don’t want the user see the separate pixels of letters in the text. Just like when you read text in your e-mail in iOS. Image size should be as small as possible. Planning physical size of image – approx. 5 cm x 15 cm.
Any help much appreciated
Thanks
To get good edges you would need to use png not jpg, which will make the image sizes much larger. I have a better suggestion, more code but better solution.
The answer is to not put the text into the image, but to draw it over it in real time.
You would:
associate text at some coordinate in the image (say a CGRect) with the image
create a uiimageview subclass that in the drawRect routine, after calling super, draws the text using the NSString categories on UIKit (which let you draw into a context)
To get going on this please create a small one vc project and get the subclass working there, then back port it to your primary project.
I want to make a color bitmap font with PNG images in the same format as Apple Color Emoji.ttf so that it can be used in iOS apps. But I can't find any references. Is it possible? If so, how to?
Version 3 of TypeTool added this feature. Use that tool to create a TTF file with the icons you want.
Once you create your TTF file, follow these instructions to embed your font in the app.
I've started using Fireworks to do prototypes, but now I need to code a prototype in HTML/CSS. I have all relevant image elements sliced, but the default behavior for Fireworks seems to be to export slides with any visible background elements embedded in the picture. E.g. When I export a logo I want the area around the logo to be transparent - I don't want the background behind the logo, which was located at a different layer.
Is it possible to export all elements with the transparency intact?
Copy your logo to a new document and export it. Lay it on top of your header graphics using CSS or maybe table if you are going that way. The point is if you see the background colors around the logo in your slice view, there is no way of exporting it transparently. The purpose of slicing is to export what you see in the sliced rectangle.
Make sure that there is no background in the image, either use the wand tool to delete the background or some other method and then make sure the images are exported as .png