2016-06-28 4 views
1

私のテーブルビューでは、tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath)にロジックがあり、セルの上端、下端、または丸みのない角に丸みがあるかどうかを判断できます。丸い角を持つUITableViewCellに削除ボタンが表示されない

override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { 

     if indexPath.row == 0 { 
      // round top 2 corners 
      let maskLayer = CAShapeLayer() 
      maskLayer.path = UIBezierPath(roundedRect: cell.bounds, byRoundingCorners: [UIRectCorner .TopLeft, UIRectCorner .TopRight], cornerRadii: CGSizeMake(4, 4)).CGPath 
      cell.layer.mask = maskLayer 
     } 

     if indexPath.section != 1 { 

      if indexPath.row == self.tableView.numberOfRowsInSection(indexPath.section) - 1 { 
       let maskLayer = CAShapeLayer() 
       maskLayer.path = UIBezierPath(roundedRect: cell.bounds, byRoundingCorners: [UIRectCorner .BottomLeft, UIRectCorner .BottomRight], cornerRadii: CGSizeMake(4, 4)).CGPath 
       cell.layer.mask = maskLayer 
      } 
     } 

    } 

これは動作しますが、私はテーブルビューに編集を実装した後に、奇妙なことは、削除ボタンに起こります。私は角の丸い削除すると

with rounded corners

without rounded corners

を、私は私がやっているかわからないんだけどこれは本当に私を混乱角の丸いコード付き

違う。誰も助けることができますか?

+0

あなたは 'cell.layer.maskToBounds = true'を追加することを試みたことがありますか? –

+0

おそらく、これをセルのビューに直接行うべきではありません。代わりに、レイヤーマスクをセルの 'contentView'に適用し、それが機能するかどうか確認してください。 – Bringo

答えて

0
override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { 

     if indexPath.row == 0 { 
      // round top 2 corners 
      let maskLayer = CAShapeLayer() 
      maskLayer.path = UIBezierPath(roundedRect: cell.bounds, byRoundingCorners: [UIRectCorner .TopLeft, UIRectCorner .TopRight], cornerRadii: CGSizeMake(4, 4)).CGPath 
      cell.contentView.layer.mask = maskLayer 
     } 

     if indexPath.section != 1 { 

      if indexPath.row == self.tableView.numberOfRowsInSection(indexPath.section) - 1 { 
       let maskLayer = CAShapeLayer() 
       maskLayer.path = UIBezierPath(roundedRect: cell.bounds, byRoundingCorners: [UIRectCorner .BottomLeft, UIRectCorner .BottomRight], cornerRadii: CGSizeMake(4, 4)).CGPath 
       cell.contentView.layer.mask = maskLayer 
      } 
     } 

    } 

使用cell.contentView.layer.mask =マスク層

+0

Hmmm ...削除ボタンが表示されますが、セルが丸く表示されていません。セルの背景色をクリアし、contentViewの背景色を白に設定しようとしましたが、赤い円の周りの領域はtableviewの背景を示しています。 – Minebomber

関連する問題