mhs5819
mhs5819

Reputation: 147

how to change text size in tableView

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:

enter image description here

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

Answers (2)

Balaji Kondalrayal
Balaji Kondalrayal

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

Muhammad Adnan
Muhammad Adnan

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.

Auto Shrink minimum font scale 0.5

Upvotes: 1

Related Questions