Search code examples
iosuitableviewswiftios8cell

Change UITableViewCell Font in iOS 8 and swift


I'm trying to change the font for my uitableviewcells,

I'm trying to use this at the moment with not success:

cell.textLabel.font = [UIFont .preferredFontForTextStyle("Avenir")];

Now i've read a lot on this and it seems I should use this instead :

    cell.textLabel.font = [UIFont fontWithName: "Avenir" size:22];

Problem is fontWithName does not seem to exist in iOS 8

any ideas??

thanks


Solution

  • The thing is that this is not Swift (it is a kind of horrifying bastardization of Objective-C):

    cell.textLabel.font = [UIFont fontWithName: "Avenir" size:22];
    

    This would be Swift:

    cell.textLabel.font = UIFont(name:"Avenir", size:22)