Change UITableViewCell Font in iOS 8 and swift

Jp4Real picture Jp4Real · May 14, 2015 · Viewed 16.1k times · Source

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

Answer

matt picture matt · May 14, 2015

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)