Problem. Can’t figure out how to corner radius my images in my custom TableView Controller. First is the original code:
import UIKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate{
@IBOutlet weak var table:UITableView!
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
}
}
Now this is what I “thought” I had to do…someone able to help?
import UIKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate{
@IBOutlet weak var table:UITableView!
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
*table.layer.cornerRadius = 20*
}
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
}
}