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:
I'm developing in Swift 2.0 for iOS 9.
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:
I'm developing in Swift 2.0 for iOS 9.
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;
}
Try this code:
cell?.contentView.layer.cornerRadius = 4.0
cell?.contentView.layer.borderColor = UIColor.blueColor().CGColor
cell?.contentView.layer.borderWidth = 1.0
You can add borderColor
, borderWidth
and cornerRadius
to the contentView
of the UITableViewCell
ContentView.Layer.BorderColor = UIColor.LightGray.CGColor;