今天偶然在视频看到这样的的一段写法,看起来比较有趣,故保存下来。借此在网上一查,说是一种高聚合的写法,这样可以增加代码的拓展性、可读性
UICollectionViewFlowLayout *layout = ({
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake(cellWH, cellWH);
layout.minimumInteritemSpacing = margin;
layout.minimumLineSpacing = margin;
layout;
});
UICollectionView *collectionView = ({
UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, BSScreenW, 0) collectionViewLayout:layout];
collectionView.dataSource = self;
collectionView.delegate = self;
[collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([BSSquareCell class]) bundle:nil] forCellWithReuseIdentifier:ID];
collectionView.scrollEnabled = NO;
collectionView;
});
网友评论