[英]Remove the white border bottom of Header View Section in Tableview Swift
我将情节提要中的分隔符样式全部删除,但标题视图底部仍显示1px白色边框。 我试图将viewdidload上的分隔符样式设置为none,并尝试使用一些扩展来删除子视图,但仍然无法正常工作。
我使用单元格在标题视图中出队并为其设置高度。 这是我的代码:
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
switch section {
case 0:
return 1
case 1:
return 1
case 2:
return 1
case 3:
return 1
case 4:
return 1
case 5:
return 1
case 6:
return 1
default:
return 1
}
}
// MARK: - View For Header
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
switch section {
case 2:
let cell = tableView.dequeueReusableCell(withIdentifier: "NewProductHeaderTableViewCell") as! NewProductHeaderTableViewCell
tableView.separatorStyle = UITableViewCellSeparatorStyle.none
cell.titleLabel.text = "Produktet e reja"
return cell
case 3:
let cell = tableView.dequeueReusableCell(withIdentifier: "NewProductHeaderTableViewCell") as! NewProductHeaderTableViewCell
cell.titleLabel.text = "Top Produktet"
return cell
case 4:
let cell = tableView.dequeueReusableCell(withIdentifier: "NewProductHeaderTableViewCell") as! NewProductHeaderTableViewCell
cell.titleLabel.text = "Me te shiturat"
return cell
default:
return nil
}
}
// MARK: - Height For Header
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
switch section {
case 2:
return 46.0
case 3:
return 46.0
case 4:
return 46.0
default:
return 0.1
}
}
override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 0
}
// MARK: - Height For Row
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
switch indexPath.section {
case 0:
return 90
case 1:
return UITableViewAutomaticDimension
case 2:
return 177
case 3:
return 177
case 4:
return UITableViewAutomaticDimension
case 5:
return 90
case 6:
return 90
default:
return 90
}
}
// MARK: - Cell For Row
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch indexPath.section {
case 0:
let cell = tableView.dequeueReusableCell(withIdentifier: "StoryTableViewCell", for: indexPath) as! StoryTableViewCell
return cell
case 1:
return UITableViewCell()
case 2:
let cell = tableView.dequeueReusableCell(withIdentifier: "NewProductTableViewCell", for: indexPath) as! NewProductTableViewCell
return cell
case 3:
let cell = tableView.dequeueReusableCell(withIdentifier: "NewProductTableViewCell", for: indexPath) as! NewProductTableViewCell
return cell
case 4:
return UITableViewCell()
case 5:
return UITableViewCell()
case 6:
return UITableViewCell()
default:
return UITableViewCell()
}
}
试试这个:
cell.separatorInset = UIEdgeInsetsZero
cell.layoutMargins = UIEdgeInsetsZero
试试这个
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
switch section {
case 2:
let cell = tableView.dequeueReusableCell(withIdentifier: "NewProductHeaderTableViewCell") as! NewProductHeaderTableViewCell
tableView.separatorStyle = UITableViewCellSeparatorStyle.none
cell.titleLabel.text = "Produktet e reja"
return cell
case 3:
let cell = tableView.dequeueReusableCell(withIdentifier: "NewProductHeaderTableViewCell") as! NewProductHeaderTableViewCell
cell.titleLabel.text = "Top Produktet"
return cell
case 4:
let cell = tableView.dequeueReusableCell(withIdentifier: "NewProductHeaderTableViewCell") as! NewProductHeaderTableViewCell
cell.titleLabel.text = "Me te shiturat"
return cell
default:
let view = UIView(frame: .zero)
view.backgroundColor = .clear
return view
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.