Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: Custom Font Robot-Bold (not working)

I have a tableview that contains custom cells with a label. I want to change the font of this label to "Roboto-Bold". But it's not working (still the same default font). What I did so far:

  • Downloaded "Roboto-Bold.ttf"
  • Add the font to my project
  • Modified info.plist adding: Fonts provided by application, item0 = Roboto-Bold.ttf
  • Added this code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    EventOptionCell *cell = (EventOptionCell *)[tableView dequeueReusableCellWithIdentifier:@"EventOptionCell"];

    switch (indexPath.row) {
        case 0:
            cell.optionLabel.text = @"TEST NEW FONT";
            cell.optionLabel.font = [UIFont fontWithName:@"Roboto-Bold" size:20];
            cell.imageView.image = [UIImage imageNamed:@"icon-test.png"];
            break;

        default:
            break;
    }

    return cell;
}
like image 593
Lücks Avatar asked Jul 17 '14 19:07

Lücks


People also ask

Does iOS support Roboto font?

Note that the Apple system fonts can only be used in Apple ecosystem products (iOs, macOS, etc). While Google's Roboto font can be used in any operating system. Keep it in mind when designing one app for both platforms.


3 Answers

Sometimes when you add a ttf file to an XCode project it will not be added to your target. This means that it will not be included in the compiled app bundle.

Select the font file in XCodes Project Navigator, then open the file inspector Utilities pane (Cmd-Option-0). You should see a "Target Membership" group there and the target of your project should have the checkbox checked. If it isn't check that and try again.

like image 126
Cornelius Avatar answered Sep 18 '22 01:09

Cornelius


If you did all above and still doesn't work. One more XCODE bug that can cause that - If you never used this custom font on storyboard/xib - add an hidden label with this font(from Interface Builder) and then suddenly it will recognise it programmatically...

-Xcode 7.3.1 - still have this bug

like image 45
DaNLtR Avatar answered Sep 17 '22 01:09

DaNLtR


If you added it to plist and project, check if font family names is exactly same as file name, they are sometimes different a little (maybe 'Robot Bold' or so) ...

Snippet which might help (from How to check if a font is available in version of iOS? )

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);
}
like image 33
PetrV Avatar answered Sep 19 '22 01:09

PetrV