本文介绍了UITableView 的圆角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试为 UITableView
圆角.但表视图没有显示.这里有什么问题?
I'm trying to round upper corners for UITableView
. But Table view is not displaying. What is wrong here ?
//TableView 设置
// TableView setup
lazy var tableView: UITableView = {
let tv = UITableView()
tv.delegate = self
tv.dataSource = self
tv.separatorStyle = .none
tv.backgroundColor = .white
tv.layer.masksToBounds = true
tv.roundUpperCorners(radius: 12)
return tv
}()
//圆上角.
func roundUpperCorners(radius: CGFloat) {
let maskPath = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: radius, height: radius))
let maskLayer = CAShapeLayer()
maskLayer.frame = self.bounds
maskLayer.path = maskPath.cgPath
self.layer.mask = maskLayer
}
推荐答案
它正在工作.感谢 Fahri Azimov 提到在设置桌子的框架后尝试圆角".
It is working. Thanks to Fahri Azimov for mentioning "Try to round the corners after setting the table's frame".
我将这一行 tableView.roundUpperCorners(radius: 12)
移动到 viewDidLayoutSubviews 中.
I moved this line tableView.roundUpperCorners(radius: 12)
into viewDidLayoutSubviews.
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
tableView.roundUpperCorners(radius: 12)
}
这篇关于UITableView 的圆角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!