IOS: custom font-robot-bold (not working)

I have a table view containing custom cells with a label. I want to change the font of this shortcut to "Roboto-Bold". But it does not work (still the same default font). What i have done so far:

  • Downloaded "Roboto-Bold.ttf"
  • Add font to my project
  • Added info.plist addition: Fonts provided by the 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; } 
+7
source share
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 application package.

Select the font file in XCodes Project Navigator, then open the File Utilities panel (Cmd-Option-0). You should see the Target Membership group, and the goal of your project should have a flag. If this is not a test and try again.

+7
source

If you added it to plist and project, check if the font family names match the file name, sometimes they are slightly different (maybe "Robot Bold" or so) ...

A snippet that can help (from How to check if the font is available in the iOS version? )

 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); } 
+1
source

If you have done everything above and still not worked. Another XCODE error that can cause this is: if you have never used this custom font in the / xib storyboard - add a hidden label with this font (from Interface Builder), and then suddenly recognize it programmatically ...

-Xcode 7.3.1 - still have this error

+1
source

Source: https://habr.com/ru/post/972410/


All Articles