Borders around images in table cells (Swift, iOS >= 14)

0
87

[ad_1]

I have the code below for configuring the content and look of cells in a table view. It works as intended, but I’d like to add a light gray border around the image.

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Picture", for: indexPath)
        
        var cellConfig = cell.defaultContentConfiguration()      
        
        let cellImage = UIImage(named: "Flags/" + pictures[indexPath.row])?.resize(withSize: CGSize(width: 50, height: 25))
        
        
        cellConfig.image = cellImage
        
        cellConfig.text = countries[indexPath.row]
        
        cell.contentConfiguration = cellConfig
        
        return cell
    }

Elsewhere in the code, I’m able to do that using something like

flag.layer.borderColor = UIColor.lightGray.cgColor
flag.layer.borderWidth = 1

where flag is a UIImageView. However, I cannot figure out how to do something analogous inside a cell. I’ve tried playing with cell.backgroundConfiguration, but that affects the entire cell, not just the image. Can anyone give me a hint? Thanks in advance

[ad_2]