Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableCell rounded border

In my iOS app, I have a table view and I would like to customise the border of my cells. I would like to reproduce an effect like the following:

enter image description here

I'm developing in Swift 2.0 for iOS 9.

like image 402
giograno Avatar asked Jan 01 '26 03:01

giograno


2 Answers

Tejas Ardeshna's answer would work, but it wont look good if borders are touching view bounds.

I would suggest add a view inside content view, keeping some padding. and then apply border to this view.

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{

    let cell = tableView.dequeueReusableCellWithIdentifier("UITableViewCell", forIndexPath: indexPath) as UITableViewCell
    if cell.viewWithTag(100) == nil
    {
        let view = UIView()
        view.frame = CGRectInset(cell.contentView.bounds, 4 , 4)
        view.layer.borderWidth = 1
        view.layer.cornerRadius = 4
        view.layer.borderColor = UIColor(red: 0, green: 0, blue: 0.6, alpha: 1).CGColor
        cell.contentView.addSubview(view)
    }
    return cell;

}
like image 139
Amit Tandel Avatar answered Jan 04 '26 12:01

Amit Tandel


Try this code:

cell?.contentView.layer.cornerRadius = 4.0
cell?.contentView.layer.borderColor = UIColor.blueColor().CGColor
cell?.contentView.layer.borderWidth = 1.0
like image 38
Tejas Ardeshna Avatar answered Jan 04 '26 13:01

Tejas Ardeshna



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!