【发布时间】:2018-04-14 19:15:35
【问题描述】:
我创建了一个带有自定义原型单元格的表格视图,但我需要塑造边框,这是我现在拥有的图像
the one i get when i run the app
请注意,我为 tableviewcell 创建了一个新类,在其中添加了要从列表中更改的文本字段
我想设置拐角半径 我尝试添加此代码,
layer.cornerRadius = 10
和
layer.masksToBounds = true
在用户定义的运行时属性中,就像我之前对按钮所做的那样,但它不起作用
代码如下:
import UIKit
class ListOffersViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
let profil = ["Eric","Eric","Eric","Eric","Eric","Eric"]
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return profil.count
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! ListOffersViewControllerTableViewCell
cell.profilName.text = profil[indexPath.row]
return cell
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
【问题讨论】:
-
您希望哪个视图设置圆角? UITavleViewCell?
-
我想让每个单元格都带有圆角和阴影,我看过其他一些帖子,但有一些代码需要添加,我不知道在哪里添加它跨度>
-
@LLIAJLbHOu 我看过这个stackoverflow.com/questions/33793211/…,但我不知道在哪里添加这段代码
-
看我的回答。我把它移到 willDisplay 函数中。