2016-07-24 6 views
1

テーブルビューセルの周りに境界線を追加しようとしています。UITableViewCellの右側にボーダーが表示されない

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) 
     cell.separatorInset.left = 20.0 
     cell.separatorInset.right = 20.0 
     cell.separatorInset.top = 20.0 
     cell.separatorInset.bottom = 20.0 
     cell.layer.borderWidth = 3 
     cell.layer.cornerRadius = 20.0 
     cell.layer.borderColor = UIColor.colorWithHexString("80CBC4").CGColor 
     return cell 
    } 

ボーダーは三辺のために働いて、右側を除く: enter image description here

enter image description here

+0

セルの幅を確認してください。 –

+0

はセルビューの 'width'と' height'制約を定義しました – triandicAnt

+0

私の最近の答えからの解決策を試してください... –

答えて

0

maskToBoundsセットtrueにレイヤのプロパティで、あなたのコードを試してみてください:cellForRowAtIndexPath内のコードを以下に示します

このプロパティの値がtrueの場合、コアアニメーションは、レイヤーの境界に一致する暗黙のクリッピングマスクを作成し、コーナー半径エフェクトを含みます。 maskプロパティの値も指定されている場合は、2つのマスクが乗算されて最終マスク値が取得されます。 このプロパティのデフォルト値はfalseです。

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) 
     cell.separatorInset.left = 20.0 
     cell.separatorInset.right = 20.0 
     cell.separatorInset.top = 20.0 
     cell.separatorInset.bottom = 20.0 
     cell.contentView.layer.borderWidth = 3 
     cell.contentView.layer.cornerRadius = 20.0 
     cell.contentView.layer.borderColor = UIColor.colorWithHexString("80CBC4").CGColor 
     cell.contentView.layer.masksToBounds = true 
     return cell 
} 
+0

'masksToBounds'で動作しません – triandicAnt

+0

' cell.layer'の代わりに 'cell.contentView.layer'を試してみましょう。 –

+0

はまだ同じ結果を持っています – triandicAnt

0

おそらく固定幅の制約を指定しています。 これを削除し、先頭および末尾の制約を指定する必要があります。

+0

問題は私が 'cellView'ではなく' tableView'のための制約を欠いていたことでした。 – triandicAnt

関連する問題