Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 817
Jp4Real Avatar asked May 14 '15 20:05

Jp4Real


2 Answers

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)
like image 113
matt Avatar answered Nov 03 '22 09:11

matt


Try the following casting way:

cell.textLabel.font = UIFont(name: "Avenir", size:22);
like image 26
Anmar Qashqish Avatar answered Nov 03 '22 09:11

Anmar Qashqish