如何在ios / swift上添加自己的标题

时间:2016-05-17 06:30:16

标签: ios swift

我试图将此特定标题添加到我的iphone应用程序中,该应用程序位于UIViewController

当前的实施

enter image description here

餐厅标题。enter image description here

我想要实现的目标

我能想到添加此特定标头的唯一解决方案是使用对象库中的图像视图

如何添加?

2 个答案:

答案 0 :(得分:1)

使用viewForHeaderInSection委托方法自定义表格sectionView

 func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
}

并且不要忘记实施该方法。

func tableView(_ tableView: UITableView,
heightForHeaderInSection section: Int) -> CGFloat

答案 1 :(得分:0)

尝试使用此代码

viewDidLoad

中设置标题标题高度
self.tableView.sectionHeaderHeight = your desired height(in int)

func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {

    let view = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: 18))
    let imageview = UIImageView(frame: CGRect(x: 20, y: 20, width: 50, height: 50))

    self.view.addSubview(imageview)

    return view
}

根据您的要求在您的imageview中设置图片

相关问题