LoginSignup
0
0

More than 5 years have passed since last update.

Swift UICollectionViewにおいてCell選択時に色を変える設定

Last updated at Posted at 2018-02-06

通常UICollectionViewのCellはタップ(選択)されてもCELLの色は変わりませんが、下記設定にて可能となる。
1、選択されたCellの色を変える設定
タップしたときの背景色
cell.selectedBackgroundView = dateManager.cellSelectedBackgroundView(UIColor.lightGrayColor())

2、セルをタップしている間は色を変え、離したら元の色に戻る処理。
func collectionView(collectionView: UICollectionView, didHighlightItemAtIndexPath indexPath: NSIndexPath) {
let cell = collectionView.cellForItemAtIndexPath(indexPath)!
cell.backgroundColor = UIColor.clearColor() // タップしているときの色にする
}
func collectionView(collectionView: UICollectionView, didUnhighlightItemAtIndexPath indexPath: NSIndexPath) {
let cell = collectionView.cellForItemAtIndexPath(indexPath)!
cell.backgroundColor = UIColor.darkGrayColor() // 元の色にする
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0