swift - 单个 UITableview 单元格中的多种字体大小(Swift)

标签 swift uitableview font-size

我有一个包含多行文本的 UITableviewCell。我想弄清楚如何使每行具有不同的字体大小。

这是我用来填充表格单元格的代码:

  func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier("eventCell")!
        cell.textLabel!.textAlignment = NSTextAlignment.Center
        cell.textLabel!.numberOfLines = 0
        cell.textLabel!.lineBreakMode = NSLineBreakMode.ByWordWrapping

        cell.textLabel!.text = self.eventsToday[indexPath.row].eventTitle + "\n" + self.eventsToday[indexPath.row].eventPlaceName

        return cell
    }

有没有一种方法可以减小“\n”换行符后的字体大小,使标有“eventPlaceName”的字符串显示为小于标有“eventTitle”的字符串?

最佳答案

使用 textLabel 对象的 attributedText 属性。

使用 attributedText 你可以格式化你的文本。

有关更多信息,请参阅 NSAttributedString

关于swift - 单个 UITableview 单元格中的多种字体大小(Swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34448378/

相关文章:

python - 如何增加文本小部件的字体大小?

css - 使用 em 单位时字体大小不正确

swift - UIBezierPath 不适用于右上角和右下角

ios - 具有自动布局的 UITableCell 配置多行 UILabel 被截断

ios - 选择行后,UITableViewCell 附件复选标记未保存在滚动条上

ios - 如何区分UITableView自定义section点击和section第一行点击?

android - 如何通过设置首选项更改应用程序的字体大小?

ios - 使用私有(private) API 读取 WiFi RSSI 值

使用动态协议(protocol)类型的 Swift 动态类型初始化

ios - WKWebView 正在切断我在 Xcode 9 和 Swift 4.0 中的其他 View