Resolved custom font for Custom UITableViewCell

Discussion in 'iOS Programming' started by erdinc27, Apr 17, 2014.

  1. erdinc27, Apr 17, 2014
    Last edited: May 2, 2014

    erdinc27 macrumors regular

    Joined:
    Jul 20, 2011
    #1
    i want to use a custom font for my application. i added font file to my app and the in info.plist i added a new row Fonts Provided By Application as an array and added my font OpenSansBold.ttf. and the font file can be seen in Build Phases also. In the table view cell i want to use that font so i wrote this.
    Code:
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *cellID = @"HaberCell";
        
        HaberCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
        
        if (cell == nil)
        {
            cell = [[HaberCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        }
        
        Haber *currentHaber = [self.arrHaberler objectAtIndex:indexPath.row];
    
        cell.haberLbl.text = currentHaber.haberTitle;
    
        cell.haberLbl.font = [UIFont fontWithName:@"OpenSansBold" size:12];
    
        return cell;
    }
    
    
    but it cant be seen in the right font format. how can i change the label's font here ?
     
  2. dantastic macrumors 6502

    dantastic

    Joined:
    Jan 21, 2011
    #2
    you're doing it right but it can be tricky to know what a font is actually named.

    start by logging this fella
    Code:
    [UIFont familyNames]
    Then find the font family you're after in the list and print out this fella
    Code:
    [UIFont fontNamesForFamilyName:@"myFont"]
    That will tell you what you should name the font you are trying to load.
     
  3. D.T. macrumors 603

    D.T.

    Joined:
    Sep 15, 2011
    Location:
    Vilano Beach, FL
    #3
    Yeah, it’s the internal font name, not the TTF filename. A quick search seems to indicate this font name should be:

    OpenSans-Bold
     
  4. TheWatchfulOne macrumors 6502

    Joined:
    Jun 19, 2009
    #4
    iOS Fonts List

    Looking at Apple's documentation, I found a very useful page that lists all fonts installed with iOS 7 and additional fonts which apps can downloaded.
     
  5. erdinc27 thread starter macrumors regular

    Joined:
    Jul 20, 2011
    #5
    thanks for the help guys. i solved the problem by your suggestions
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Can you tag the thread as Resolved then? Thanks.
     

Share This Page