UITableCell圆形边框

问题描述 投票:3回答:4

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

enter image description here

我正在开发适用于iOS 9的Swift 2.0。

ios swift uitableview
4个回答
5
投票

Tejas Ardeshna的答案会起作用,但如果边界触及视界,它看起来不会很好。

我建议在内容视图中添加一个视图,保留一些填充。然后将边框应用于此视图。

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;

}

3
投票

试试这段代码:

cell?.contentView.layer.cornerRadius = 4.0
cell?.contentView.layer.borderColor = UIColor.blueColor().CGColor
cell?.contentView.layer.borderWidth = 1.0

1
投票

你可以添加qazxsw poi,qazxsw poi和qazxsw poi到borderColor的qazxsw poi


0
投票
borderWidth
© www.soinside.com 2019 - 2024. All rights reserved.