Friday, February 10, 2017
How to Create a Custom Header View in Tableview Using Swift
1.Create a Subclass of UITableViewCell named as CustomHeaderCell.swift
2.click to create XIB file
3.Add the label Below shown in fig
CustomHeaderCell.swift
import UIKit
class CustomHeaderCell: UITableViewCell
{
@IBOutlet var headerLabel: UILabel!
override func awakeFromNib()
{
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool)
{
super.setSelected(selected, animated: animated)
}
}
//MARK: - Table Header view
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?
{
let headerView = CustomHeaderCell.loadFromNibNamed(nibNamed: "CustomHeaderCell") as! CustomHeaderCell
headerView.headerLabel.text = "Header"
return headerView
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat
{
return 25.0
}
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment