【发布时间】: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