<分区>
我有这个带有静态单元格的 UITableView:
我想更改标题字段并在单元格中水平居中。我该如何使用 Swift?
提前致谢。
标签 ios swift uitableview
最佳答案
首先,您当然可以使用 swift 来完成此操作,现在这是您需要放入 viewController 中以完成此操作的代码
你需要把你的viewController作为UITableViewDelegate
然后实现这个方法
func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return X; //X is the value of height of your header
}
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerView = UIView(frame: CGRect(x: 0, y: 0, width: self.tableView.frame.size.width, height: X)) //X is the value of height of your header
let label = UILabel(frame: headerView.frame)
label.text = "TESTING"
label.textAlignment = NSTextAlignment.Center
headerView.addSubview(label)
return headerView;
}
希望对你有帮助
关于ios - 更改 UITableView 静态单元格中的标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37661137/
相关文章:
ios - 在 UITableView 中,如何在隐藏行之后关闭行的底部边框?
ios - Dailymotion 播放器无法在 UIWebview Swift 3 中工作
ios - UIPanGestureRecognizer 将事件传递给下面的按钮
ios - 如何使用 Swift 将通知数据传递给 View Controller
swift - XCode/swift : How to get Value of Popup Button
ios - UITextView 的 UIGestureRecognizer 阻止键盘在点击时出现
uitableview - 避免 iOS 11 下 UITableViewCell 的额外前导边距