ios - 表格单元格圆角边框

标签 ios swift uitableview

在我的 iOS 应用程序中,我有一个表格 View ,我想自定义单元格的边框。我想重现如下效果:

enter image description here

我正在为 iOS 9 使用 Swift 2.0 进行开发。

最佳答案

Tejas Ardeshna 的答案会奏效,但如果边界接触到 View 边界,它看起来就不会好看。

我建议在内容 View 中添加一个 View ,并保留一些填充。然后将边框应用于此 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;

}

关于ios - 表格单元格圆角边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35909460/

相关文章:

iphone - Google Drive SDK- iOS 应用程序中的音频和视频流

ios - 从 JSON API 附加到数组

ios - 第一个UITableViewCell不调用didSelectRowAtIndexPath

swift - 我如何使用 Swift 3 在 SpriteKit 中画一条线?

ios - 如何使用字典将行添加到 TableView 中的特定部分?

swift - tableView.reloadData 不更新 UI

ios - UIview 在调用 View Controller 时没有响应

android - 移动网络中的推送通知

ios - 如何为 UITableViewCell 找到 ViewController?

Swift:从日期选择器获取正确的时区?