Custom Fonts in iOS 7

Custom fonts in iOS 7

First of all I'm assuming that SpriteKit doesn't make any difference.

  1. You need your font in .otf or .ttf copied to your project. For example in Supporting Files.
  2. You need to edit .plist file. Add "Fonts provided by application" key into your plist and in Item 0 copy the exact filename of the font you copied to your Supporting files WITH extension. For example: "JosefinSansStd-Light_0.otf"
  3. Make sure that the font you imported to your app is being packed into app itself. Do that by selecting your Target, then Build Phases, then Copy Bundle Resources. If you don't see your font in there, drag it from Supporting Files.

Finally, you would like to list all your fonts when the app starts just to see useable name for your font. You will do that with this little piece of code:

NSArray *fontFamilies = [UIFont familyNames];
for (int i = 0; i < [fontFamilies count]; i++)
{
NSString *fontFamily = [fontFamilies objectAtIndex:i];
NSArray *fontNames = [UIFont fontNamesForFamilyName:[fontFamilies objectAtIndex:i]];
NSLog (@"%@: %@", fontFamily, fontNames);
}

Search for your font in printed results, for example, I would search for "Josefin" and I would see that actual font name is "JosefinSansStd-Light". After that you only need to use that font by:

UIFont *customFont = [UIFont fontWithName:@"JosefinSansStd-Light" size:20];

In iOS8 you add your fonts directly to the project and they are visible in the interface builder.
Modify your code to account for this but programmatically setting font for iOS7 and selecting it in xCode6 interface builder. PS. Interface builder in xCode6 gives you the correct font name that you can copy-paste into the code below.

#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)

if(SYSTEM_VERSION_LESS_THAN(@"8.0"))
{
UIFont *customFont = [UIFont fontWithName:@"OpenSans-Light" size:32];
self.registerLabel.font = customFont;
}

Hope this helps, cheers.

UITextView renders custom font incorrectly in iOS 7

I debugged this issue a little, and it seems to be a bug in the way NSLayoutManager layouts the text. As other answers pointed out, UITextView is build around TextKit since iOS7, and thus uses NSLayoutManager internally to layout text. UILabel uses Core Text to layout text directly. Both eventually use Core Text to render the glyphs.

You should open a bug report with Apple and post the number so people can duplicate it. The issue has not been fixed so far in iOS7.1 betas.

As a workaround, you can replace UITextView with other Core Text alternative editors, which layout and render directly with Core Text, where the issue does not exist.

I tested SECoreTextView, and it shows the text correctly. It implements a similar API to UITextView but internally uses Core Text.

Here is how it looks after swapping UITextView with SECoreTextView:

SETextView *textView = [[SETextView alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
textView.center = CGPointMake(self.view.center.x, self.view.center.y+40);
textView.font = [UIFont fontWithDescriptor:desc size:24];
textView.text = @"ܩ̈ ܡ̄ ܬ̇ ܒ̃";
textView.textColor = [UIColor blackColor];
textView.backgroundColor = [UIColor whiteColor];
textView.editable = YES;

[self.view addSubview:textView];

Using Core Text, the layout issue does not exist.

How can I change text font in UIPickerView in iOS 7?

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UILabel* tView = (UILabel*)view;
if (!tView)
{
tView = [[UILabel alloc] init];
[tView setFont:[UIFont fontWithName:@"Helvetica" size:14]];
//[tView setTextAlignment:UITextAlignmentLeft];
tView.numberOfLines=3;
}
// Fill the label text here
tView.text=[wishvalues objectAtIndex:row];
return tView;
}

UILabel custom fonts works only on iOS7

Try like that:

- (id)initWithCoder:(NSCoder *)coder {
self = [super initWithCoder:coder];
if (self) {
dispatch_async(dispatch_get_main_queue(), ^{
self.font = [UIFont fontWithName:@"fbTypoPas-Black" size:34];
self.textColor = [UIColor whiteColor];
});
}
return self;
}


Related Topics



Leave a reply



Submit