UITableView in swift
//Create Table View
var myTable = UITableView()
myTable.frame = CGRect(x: 0, y: 0, width: Int(Constants.ScreenWidth), height: Int(Constants.ScreenHeight-130))
myTable.delegate = self
myTable.dataSource = self
myTable.backgroundColor = UIColor.white
myTable.separatorColor = UIColor.clear
self.view.addSubview(myTable)
//Table view delegate and datasources methods
//MARK: - Table view Delegate -
func numberOfSections(in tableView: UITableView) -> Int {
// Return the number of sections.
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// Return the number of rows in the section.
return 10;
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 68
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
myTable.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
var cell:UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell")! as UITableViewCell
cell = UITableViewCell.init(style: UITableViewCellStyle.default, reuseIdentifier: "cell")
cell.layer.shouldRasterize = true
cell.layer.rasterizationScale = UIScreen.main.scale
cell.selectionStyle = UITableViewCellSelectionStyle.none
let backView:UIView = UIView(frame: CGRect(x: 5, y: 0, width: Constants.ScreenWidth-10, height: 63))
backView.layer.shadowColor = UIColor.lightGray.cgColor;
backView.layer.shadowOpacity = 0.2;
backView.layer.shadowOffset = CGSize(width: 2.0, height: 2.0)
backView.layer.shadowRadius = 0.0;
backView.backgroundColor = UIColor.white;
backView.layer.borderWidth = 0.2;
backView.layer.cornerRadius = 5;
backView.layer.borderColor = UIColor.lightGray.cgColor;
cell.contentView.addSubview(backView);
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
}