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?
Swift 5
cell.textLabel?.font = UIFont.systemFont(ofSize: 30.0)
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...
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With