Reputation: 147
Can anyone tell me how to change the text size in a tableView so that the text in the screenshot below fits within the width of the screen:
The current tableView code is:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
cell.textLabel!.text = self.dataArray[indexPath.row]
cell.imageView!.image = UIImage(named: "20x20_empty-round-radiobutton-choice-ui")
return cell
}
Thanks in advance!
Upvotes: 1
Views: 4280
Reputation: 1751
Try the following code:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
cell.textLabel!.text = self.dataArray[indexPath.row]
cell.textLabel.font = UIFont(name: cell.textLabel.font.fontName, size:15) // Change the font size as per your requirement
cell.imageView!.image = UIImage(named: "20x20_empty-round-radiobutton-choice-ui")
return cell
}
Upvotes: 2
Reputation: 2668
Set autoshrink minimum fontScale. If your text is long enough to exceed the actual Label Frame,then your font will be shrinked upto minimum font scale you provide in storyboard or xib.
Upvotes: 1