如何在静态单元格中自定义标题部分? [英] How to customise header section in static cell?

查看:144
本文介绍了如何在静态单元格中自定义标题部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程序中自定义标题部分,但它在静态单元格中。我试图通过包含标识符使一个单元格成为我的标题,并添加一个新文件来控制该单元格,但这不起作用。我试图将一个对象拖到新文件中,但它无法完成。那么如何自定义节头?我的接近方式是好的吗?

I want to customise the header section in my application but it's in static cell. I tried to make one cell to be my header by including identifier and add a new file to control that cell but that doesn't work. I tried to drag an object into new file but it's can't be done. So how to customise section header? Is my way of approach is good?

推荐答案

有几种方法可以自定义 UITableView中的标题部分。例如,如果您要做的只是更改文本,则可以在属性检查器中执行此操作,同时确保选择 TableViewSection

There are a couple of ways to customize the header section in a UITableView. For instance, if all you want to do is change the text, you can do so in the attributes inspector while making sure your TableViewSection is selected:

但是,如果您希望能够进行自定义,例如文本大小,tont,大小写 - UILabels固有的任何自定义,您需要从<$ c $覆盖此方法C>的UITableViewController :

However, if you want the ability to do customizations such as text size, tont, capitalizations - any customizations inherent to UILabels, you'll need to override this method from the UITableViewController:

  override func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
    let header = view as! UITableViewHeaderFooterView
    header.textLabel.textColor = UIColor(red: 243/255, green: 153/255, blue: 193/255, alpha: 1.0)
    header.textLabel.font = UIFont(name: "Helvetica Neue", size: 18)
    header.textLabel.text = "About Us"
    header.textLabel.frame = header.frame
    header.textLabel.textAlignment = NSTextAlignment.Left
  }

例如,在上面的代码中,我采用了作为参数传递的标头并配置了textColor,font,text,alignment - 你可以在这里完成你在UILabel上可以做的任何事情。

For example, in the code above, I took the header that was passed as a parameter and configured the textColor, font, text, alignment - really anything you can do on the UILabel can be done here.

自定义之前

自定义后

这篇关于如何在静态单元格中自定义标题部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆