我想在Xcode中使用Swift为嵌套在自定义单元格和自定义表格视图中的图像添加圆角半径。这是我的代码。有人知道如何应用.cornerRadius = 10
吗?
struct Beer {
let title: String
let imageName: String
}
//Enter cell lines here for new beers
let data: [Beer] = [
Beer(title: "Helles Half Life", imageName: "HellesHalfLife"),
Beer(title: "Racemic Red Ale", imageName: "RedAle"),
Beer(title: "RSIPA", imageName: "RSIPA"),
Beer(title: "Stage II HAC", imageName: "HellesHalfLife"),
Beer(title: "Helleva Stage II Lager", imageName: "HellevaStageII"),
Beer(title: "Train of Four Stout", imageName: "TrainOfFour"),
Beer(title: "Patrick's Feeling Hazy", imageName: "PatricksFeelingHazy"),
Beer(title: "BIS 40", imageName: "BIS40"),
Beer(title: "40 Winks", imageName: "FortyWinks"),
Beer(title: "", imageName: ""),
]
override func viewDidLoad() {
super.viewDidLoad()
table.dataSource = self
table.delegate = self
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let Beer = data[indexPath.row]
let cell = table.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableViewCell
cell.label.text = Beer.title
cell.iconImageView.image = UIImage(named: Beer.imageName)
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) ->
CGFloat{
return 120
}
我尝试在table.delegate
下的override func viewDidLoad()
部分添加table.layer.cornerRadius = 10
。
2条答案
按热度按时间n3schb8v1#
在TableViewCell类文件中,
也可以在cellForRowAt中添加cornerRadius:
lsmepo6l2#
您可以在视图中添加imageview,然后
或