私はiOSでアプリケーションを構築しています。私のCollectionViewのセルをタッチすると、通常のボタンとほとんど同じように強調します。 didSelectItemAtIndexPath:(NSIndexPath *)indexPathメソッドでこれをどのように達成できますか?CollectionViewのセルをハイライトします
おかげ
私はiOSでアプリケーションを構築しています。私のCollectionViewのセルをタッチすると、通常のボタンとほとんど同じように強調します。 didSelectItemAtIndexPath:(NSIndexPath *)indexPathメソッドでこれをどのように達成できますか?CollectionViewのセルをハイライトします
おかげ
このような何かを試してみてください:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
.....
if (cell.selected) {
cell.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:153/255.0 alpha:1]; // highlight selection
}
else
{
cell.backgroundColor = [UIColor clearColor]; // Default color
}
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
UICollectionViewCell* cell = [collectionView cellForItemAtIndexPath:indexPath];
cell.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:153/255.0 alpha:1]; // //cell.lblImgTitle.text = @"xxx";
}
- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath{
UICollectionViewCell* cell = [collectionView cellForItemAtIndexPath:indexPath];
cell.backgroundColor = [UIColor clearColor];
}
didHighlightItemAtIndexPathメソッドとdidUnhighlightItemAtIndexPathメソッドのセル内の画像のアルファを変更して解決しました。とにかく、私は正しい答えとしてあなたの答えを設定します。ありがとう。 –
答えであなたの問題をどのように解決したのですか?それは他の人に役立つだろう... diogo-appdev –
はあなたがセルクラスをサブクラス化した場合、この
cell.selectedBackgroundView.backgroundColor = [UIColor greenColor];
を試してみてください、あなたの.mファイルでこれを入れ
- (void)setSelected:(BOOL)selected
{
if(selected)
{
self.backgroundColor = [UIColor colorWithWhite:0.1 alpha:0.5];
}
else
{
self.backgroundColor = [UIColor whiteColor];
}
}
変更できない理由カカオポッドによる背景色?私は新しいユーザ定義コレクションビューのセルクラス `
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
CHSMenuControlCell *cell = (CHSMenuControlCell*)[collectionView cellForItemAtIndexPath:indexPath];
cell.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:153/255.0 alpha:1]; // //cell.lblImgTitle.text = @"xxx";
}
- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath{
CHSMenuControlCell *cell = (CHSMenuControlCell *)[collectionView cellForItemAtIndexPath:indexPath];
cell.backgroundColor = [UIColor clearColor];
}
そのセルの背景色を変更します。 – user1673099