Reputation: 4506
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?
Upvotes: 11
Views: 15147
Reputation: 2093
Swift 5
cell.textLabel?.font = UIFont.systemFont(ofSize: 30.0)
Upvotes: 6
Reputation: 329
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
Upvotes: 4
Reputation: 454
What you need is a self-sizing cell, which can determines its size to fit its content. Self-sizing cell is introduced in iOS 8. If you are using AutoLayout for your cells, things will work nicely after a few tweaks. Please watch "What's New in Table and Collection Views" session at WWDC 2014 for more information.
Upvotes: 0
Reputation: 23078
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...
Upvotes: 5