Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableCell Font Size (In Swift)

I have tried lots of combinations but can't seem to get the font size to be reduced in Xcode 6 / Swift. I basically have 6 line items in a table cell, but it only fits 3 (i'd like to make the font smaller in hopes that it will show more and potentially not scroll or scroll as much).

Here is my code:

func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
    var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell

        cell.textLabel.adjustsFontSizeToFitWidth = true
        cell.textLabel.minimumScaleFactor = 0.1
        cell.textLabel.minimumFontSize = 10.0
        cell.textLabel.font = UIFont.systemFontOfSize(10.0)
    cell.textLabel.text = String(reportData[indexPath.row] as NSString)


    return cell
}

Although i'm aware it's not best practice to set every single thing above (scale factor, font size, new font, etc, etc, etc, I just wanted to show that I've tried everything).

Do you all know of any bugs or issues where some of the above wouldn't work? What's the proper way to set the font size of each cell?

like image 851
NullHypothesis Avatar asked Jul 18 '14 01:07

NullHypothesis


3 Answers

Swift 5

cell.textLabel?.font = UIFont.systemFont(ofSize: 30.0)
like image 59
Mike Volmar Avatar answered Sep 22 '22 16:09

Mike Volmar


I recently played around with font sizes and noticed that nothing get's displayed when the font size is smaller than 11.

According to the Apple iOS Human Interface Guidelines:

Text should never be smaller than 11 points, even when the user chooses the extra-small text size.

Just a thought...

like image 35
zisoft Avatar answered Sep 23 '22 16:09

zisoft


Swift Answer:


If you want the font to adjust and fit to the width of the cell. I used this when I had an accessory view.

cell.textLabel?.adjustsFontSizeToFitWidth = true
like image 29
fonz Avatar answered Sep 21 '22 16:09

fonz