• IOS -- UICollectionView里面的cell点击,点击一个cell改变其他cell的状态


    view.m

    - (void)initWithCreatorCollectView
    {
        //模拟数据
        [self imitateData];
        
        float width = ([UIScreen mainScreen].bounds.size.width - 55)/2.0;
        float height = 45;
        float rowCount = _buyBtnDataArr.count / 2.0;
        _collecViewHeight = ceilf(rowCount) * (height + 15);
        _flowLayout = [[UICollectionViewFlowLayout alloc] init];
        _flowLayout.minimumInteritemSpacing = 13;//左右边距
        _flowLayout.minimumLineSpacing = 5;//上下边距
        _flowLayout.sectionInset = UIEdgeInsetsMake(1, 1, 0, 1);
        //设置collectionView滚动方向
        _flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
        _flowLayout.itemSize = CGSizeMake(width, 60);
        
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width-40, _collecViewHeight) collectionViewLayout:_flowLayout];
        _collectionView.backgroundColor = [UIColor clearColor];
        [_collectionView registerClass:[HMSemiBuyBtnCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
        _collectionView.dataSource = self;
        _collectionView.delegate = self;
        _collectionView.delaysContentTouches = NO;//使view里面的btn点击明显
        _collectionView.scrollEnabled = NO;//不可滑动
        _collectionView.showsVerticalScrollIndicator = NO;//隐藏滚动条
        
        
        //设置默认选中按钮的样式
        [_collectionView selectItemAtIndexPath:[NSIndexPath indexPathForItem:1 inSection:0]  animated:YES scrollPosition:UICollectionViewScrollPositionNone];
        
        
        [self addSubview:_collectionView];
    }

    cell.m

    - (void)setSelected:(BOOL)selected
    {
        NSLog(@"%@",selected?@"YES":@"NO");
      
        if (selected) {//选中
            [self.buyChapterBtn setUserInteractionEnabled:NO];
            [self.buyChapterBtn setTitleColor:[UIColor colorWithHexString:@"F94F50"] forState:UIControlStateNormal];
            self.buyChapterBtn.layer.borderColor = [UIColor colorWithHexString:@"F94F50"].CGColor;
            NSLog(@"asasasas-1");
        }else {//未选中
            [self.buyChapterBtn setUserInteractionEnabled:YES];
            [self.buyChapterBtn setTitleColor:[UIColor colorWithHexString:@"333333"] forState:UIControlStateNormal];
            self.buyChapterBtn.layer.borderColor = [UIColor colorWithHexString:@"D6D6D6"].CGColor;
            NSLog(@"asasasas-2");
        }
        [super setSelected:selected];
    }
  • 相关阅读:
    玄学最短路算法——Ex Floyd
    题解 CF785E 【Anton and Permutation】
    题解 P1825 【[USACO11OPEN]玉米田迷宫Corn Maze】
    实现非递归树链剖分
    题解 P3423 【[POI2005]BAN-Bank Notes】
    题解 P3871 【[TJOI2010]中位数】
    【带修改的主席树】理解题解 (P2617 【Dynamic Rankings】题解)
    快速计算高精乘低精---低精优化高精
    了解 yaml文件格式
    com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'test.ac_flight' doesn't exist
  • 原文地址:https://www.cnblogs.com/qiyiyifan/p/7641915.html
Copyright © 2020-2023  润新知