iOS collectionview 单选

1.默认选中第一个item

dispatch_async(dispatch_get_main_queue(), ^{

        if(indexPath.item == 0) {

            [collectionView selectItemAtIndexPath:indexPath animated:YESscrollPosition:(UICollectionViewScrollPositionNone)];

        }

    });

2.在自定义cell里

- (void)setSelected:(BOOL)selected {

    [supersetSelected:selected];

    if(selected ==YES) {

        self.contentView.backgroundColor = kColor(@"#794FF1");

        self.titleL.textColor = UIColor.whiteColor;

    }else{

        self.contentView.backgroundColor = kColor(@"#EBE3FF");

        self.titleL.textColor = kColor(@"#9C9C9C");

    }

}

你可能感兴趣的:(iOS collectionview 单选)