I have a game which I would like the time and score to be displayed in a custom font.
How does one display their own fonts, or would I need to write an algorithm which controls a list of number images e.g. 1, 2, 3 etc. and displays them e.g. 134
Some more info would be useful. When you are just using simple iPhone controls, like an UILabel, you can just add fonts to your project and mention them in the UIAppFonts section of your apps plist.
Otherwise I would suggest using an image map, containing all the characters you need. Cocos2D contains easy stuff for this kind of "problems".
Related
I am trying to make an app that will let users select different fonts and rotate them around as desired.
What I need to know is what technology is being used in this app (see screenshots below)?
Is it UIKit, CATextLayer?
Are these texts / fonts available out of the box in apples UIKit module?
How can you let user resize or rotate text fonts.
Is there any sample apple project or sample code in github that I can use to look at?
All that looks like it can be done with custom fonts, none of them will be found in UIKit. You'll need to buy or find fonts that you have the rights to distribute. Here's a good reference for adding custom fonts to your project.
Once you have fonts installed. UILabel and other text holding controls can have their .font properties queried and set. And anything else you'd like to do to a view (like set up a rotational transform) is applicable to those controls, too.
I would like to implement rich format text views as are demonstrated in Instagram. Following is a screenshot.
Specifically, my goals are:
Words at different positions of the same text view may have different font sizes, font colors and font styles(bold, italic, etc).
Touch events (long press, touch down, etc) can be detected in the delegate callbacks. Information (which word is touched, whether it's a long press or a touch down, etc) can be gathered in such callback methods.
Big frameworks like Three20 are out of the question. Small, independent libraries are highly preferred. Low level Cocoa Touch APIs may also be OK if it won't take me more than a few days to wrap them up.
Any suggestions are highly appreciated.
NSAttributedString lets you do this. If you have access to the iOS 5 developers cookbook by Erica Sadun there is a recipe for a wrapper around NSMutableAttributedString which makes it simple to add text piece by piece, changing attributes as you go.
Here is the source on Erica's githuib
Finally found an ideal open source solution (supports both iOS 5.0 and iOS 6): the OHAttributedLabel, which is capable of both rich format and touch handling.
https://github.com/AliSoftware/OHAttributedLabel
I'm developing an application. It consists of notes and images also. I'm unable to find the best way of coding to add images and text together.
I want to add the images between the textview and after that, the text has to continue. Is it possible to do like this?
You will probably be better to use a webview and load in some static html from the application unless you particularly need textviews, in which case look at holding things in UITableView
I'd like to offer my app users a couple of different skins to use for the app, a default black skin and then say a white skin. Maybe allow them to set fonts and / or font color site wide for headers or whatever.
What would be the best approach to do this? Obviously I don't want this to affect the speed of my application.
You basically have 3 options.
HTML5 + CSS in UIWebView
Depending on your needs, the most flexible way would be to provide part of the user interface via UIWebView as HTML5 and CSS, and let the users (or theme makers) create different CSS based styles. This is what most applications do; IM+ or Colloquy for instance.
Modifying the native controls by subclassing them
Apple might reject apps that modify the native controls and views. So that is not a secure option if you want to submit your app to the App Store.
Create your own UIView subclasses and implement their behavior
Option three would be to draw your own controls using subclasses of UIView, but that might be more work than it's worth. You find this in many games on iOS.
For storing and accessing properties like colors and other parameters that make up the user interface, I'd suggest using something simple.
In some of my apps I use a JSON file (or alternatively XML - but that's more work to parse). There is TouchJSON (github.com/schwa/TouchJSON) which does an excellent job in simply converting a file into an NSDictionary, which is easily accessible. You could, for instance, store colors and font names and sizes in such a file and read one of them at launch time.
Is it possible to use the CFAttributedString type to draw formatted text on the iPhone? I see it in the documentation, but I can't figure out how to actually draw it to a context.
Three20 has a formatted text field. Basically Joe Hewitt implemented a light HTML interpreter to render the text, so it is much faster than a webview. fast enough to be used in a tableview.
The workaround is to use a WebKitView. Format your text as HTML and display in a mini web view at whatever size you need.
Actually, it turns out this is answered in the iPhone documentation, I just didn't read it carefully enough:
iPhone OS Note: While Core Foundation on iPhone OS contains CFAttributedString, there are no additions to the APIs in UIKit to add specific attributes such as font, style, or color, and there are no APIs to draw attributed strings.
There you go, no free formatted text. Bummer.
Kyle
There's an undocumented method on TextView to pass in HTML formatted text (it's really a kind of web view underneath). A number of apps in the store make use of it, just make sure your app works without it there.