简体   繁体   English

如何在tableView中更改文本大小

[英]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: 任何人都可以告诉我如何更改tableView中的文本大小,以便下面的屏幕截图中的文本适合屏幕的宽度:

在此输入图像描述

The current tableView code is: 当前的tableView代码是:

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! 提前致谢!

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
}

Set autoshrink minimum fontScale. 设置自动收缩最小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. 如果您的文本足够长以超过实际的标签框架,那么您的字体将缩小到您在storyboard或xib中提供的最小字体比例。

自动收缩最小字体比例0.5

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM