【问题标题】:cannot change font in uitableviewcell using swift无法使用 swift 更改 uitableviewcell 中的字体
【发布时间】:2014-07-01 21:46:08
【问题描述】:

我无法更改字体,我什至尝试过func tableView(tableView: UITableView!, willDisplayCell cell: UITableViewCell!, forRowAtIndexPath indexPath: NSIndexPath!)。 我可以毫无问题地更新文本标签

这是根据表格单元格索引选择字体的方法

func fontForDisplayAtIndexPath(indexPath:NSIndexPath) ->UIFont?{
    if(indexPath.section == 0) {

        var ind = indexPath.row
        var names = familyNames as String[]

        var fontFamilyName = names[ind]
       // println(names[ind])

        var fontName = (UIFont.fontNamesForFamilyName(fontFamilyName) as String[])[0]
        println(fontName)

        return  UIFont(name: fontName, size: cellPointSize)

    } else { return nil}

}

override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!{

    var cell:UITableViewCell
    var familyNameCellID = "FamilyName"
    var favoritesViewCellID = "Favorites"

    if(indexPath.section == 0)
    {

        cell = tableView.dequeueReusableCellWithIdentifier(familyNameCellID, forIndexPath: indexPath) as UITableViewCell
        if(cell == nil) 
        {
            cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: familyNameCellID)
        }
        cell.textLabel.font = fontForDisplayAtIndexPath(indexPath)
        cell.textLabel.text = familyNames[indexPath.row]
        cell.detailTextLabel.text = familyNames[indexPath.row]

    }
    else
    {

        cell = tableView.dequeueReusableCellWithIdentifier(favoritesViewCellID, forIndexPath: indexPath) as UITableViewCell

    }
return cell
}

【问题讨论】:

  • 你确定fontForDisplayAtIndexPath确实返回了一些东西吗?
  • 是的...我什至尝试将 cell.textLabel.font = UIFont(name: "Verdana", size: 18) 设置为直接测试
  • 有没有人尝试在swift中成功更改uitableviewcell字体?我正在使用 6/17 beta 2 版本的 xcode

标签: xcode uitableview fonts swift beta


【解决方案1】:

我多次重启xcode后问题消失了。我的代码确实可以更改字体。 Xcode 6 beta 2 只是一个小错误。我在 xcode 上遇到过很多崩溃。如果代码中存在构建错误,则在编译显示“索引”时包括它挂起。

【讨论】:

    猜你喜欢
    • 2015-07-26
    • 2015-08-05
    • 1970-01-01
    • 1970-01-01
    • 2020-05-16
    • 2013-03-23
    • 2023-03-04
    • 2015-02-18
    • 2010-09-20
    相关资源
    最近更新 更多