gpt4 book ai didi

ios - 我如何编辑表格 View 部分标题 ios swift

转载 作者:搜寻专家 更新时间:2023-11-01 05:57:04 25 4
gpt4 key购买 nike

我在我的三个部分中的每一个部分都使用了一个带有标题的 TableView Controller 。我希望能够更改 header 的外观,最好的方法是什么。

类似于 snapchat 故事页面标题的外观

最佳答案

您可以通过在 Storyboard中创建自定义的 UITableViewCell 来自定义您的部分标题。

您设计 3 个部分,就像 Storyboard中的快照一样。

这是我使用的两个不同 UITableView 单元格的两个部分的示例

func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {    
//Say 2 section with two different look
if section == 0{
let header = tableView.dequeueReusableCellWithIdentifier("HeaderTableViewCell1")! as! HeaderTableViewCell1
header._lblGroupName.text = ""
header._btnExpand.addTarget(self, action: "hideSection:", forControlEvents: .TouchUpInside)

header._lblTotalCount.text = ""
return header.contentView
}
else{
let header = tableView.dequeueReusableCellWithIdentifier("HeaderTableViewCell2")! as! HeaderTableViewCell2
header._lblGroupName.text = ""
header._btnExpand.addTarget(self, action: "hideSection:", forControlEvents: .TouchUpInside)

header._lblTotalCount.text = ""
return header.contentView
}
}

创建两个自定义 UITableViewCell 类。设置出风口

class HeaderTableViewCell1: UITableViewCell {

@IBOutlet weak var _lblTotalCount: UILabel!
@IBOutlet weak var _btnExpand: UIButton!
@IBOutlet weak var _lblGroupName: UILabel!

}

class HeaderTableViewCell2: UITableViewCell {

@IBOutlet weak var _lblTotalCount: UILabel!
@IBOutlet weak var _btnExpand: UIButton!
@IBOutlet weak var _lblGroupName: UILabel!

}

关于ios - 我如何编辑表格 View 部分标题 ios swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37981852/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com