0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Swift2 UICollectionViewのCell選択時のCellのBackgroundColorの設定

Posted at

UICollectionViewのCell選択では標準ではCell選択されても色が変わらないが下記の記述で指定できる。
1、タップしたときの背景色
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?