I want to generate same Random color for selected cell and background cell. I have successfully implemented it with flowing code . but with this i am getting cell.background color correctly but i want to set light color on each indexpath of selected cell. so, how can i do it ? suppose ,
if (indexpath.row ==1) {
// lightcolor
}
if (indexpath.row == 2) {
// More light color as compare to indexpath.row ==1
}
@interface DisplayViewController () {
DisplayCollectionViewCell *cell;
float randomRed,randomGreen,randomBlue;
}
- (void)viewDidLoad {
randomRed = arc4random() % 255;
randomGreen = arc4random() % 255;
randomBlue = arc4random() % 255;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"DisplayCellIphone" forIndexPath:indexPath];
if (indexPath.row == _setRandomIndex) {
// For Selected Color
cell.layer.backgroundColor = [UIColor colorWithRed:randomRed * 0.9 /255.0 green:randomGreen * 0.9 /255.0 blue:randomBlue * 0.9/255.0 alpha:1].CGColor;
} else {
cell.backgroundColor = [UIColor colorWithRed:randomRed/255.0 green:randomGreen/255.0 blue:randomBlue/255.0 alpha:1.0];
}
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
_count ++;
randomRed = arc4random() % 255;
randomGreen = arc4random() % 255;
randomBlue = arc4random() % 255;
if (indexPath.row == _setRandomIndex) {
if (_count == 0) {
[self addData:4];
}
NSLog(@"Selected Right Cell");
if (_count == 1 || _count == 2) {
_setRandomIndex = arc4random() % 6;
[self addData:6];
// _setRandomIndex = 2;
}
// next cell till 20;
}