everyone!
My problem sound like this:
I want to make my custom cell rounded in my app in iPhone. But when I try to do something like this:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as? MainTableViewCell
else { fatalError("DequeueReusableCell failed while casting") }
cell.imageView?.layer.cornerRadius = cell.frame.size.height / 2
cell.imageView?.clipsToBounds = true
cell.imageView?.contentMode = .scaleAspectFill
cell.textLabel?.textColor = #colorLiteral(red: 0.03921568627, green: 0.3969546359, blue: 1, alpha: 1)
cell.textLabel?.font = UIFont(name: "EuphemiaUCAS", size: 22)
cell.textLabel?.text = restaurantNames[indexPath.row]
cell.textLabel?.numberOfLines = 0
cell.imageView?.image = UIImage(named: restaurantNames[indexPath.row])
return cell
}
// MARK: - Table View Delegate
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 85
}
I have a strange result: Result #1
But when I change this line:
cell.imageView?.layer.cornerRadius = cell.frame.size.height / 2
To this:
cell.imageView?.layer.cornerRadius = 85 / 2
As you can see, everything is in order: Result #2
But this is not the right way to solve the problem
Thanks for all answers!