更好的支持iOS 5实现网格视图效果,用UITableView 实现。
IOS 6 以后可以用UICollectionView 使用更方便,而且collectiionView提供更多的布局自定义类,可以实现更炫酷的效果;
本文主要是以uitableview 的行为基础,然后在每个cell上再添加布局 各个自定义的itemView(uiview)。
使用如下:
<span style="font-size:18px;background-color: rgb(255, 255, 204);">- (FWGridViewCell *) gridView:(FWGridView *)grid cellForGridIndex:(FWGridViewIndex *)gridIndex
{
FWGridViewCell *cell = [grid dequeueReusableCell];
if (!cell) {
cell = [[FWGridViewCell alloc] initWithCellStyle:FWGridViewCellStyleTitle];
}
cell.thumbnail.image = [UIImage imageNamed:@"wechat"];
// cell.thumbnail.highlightedImage = [UIImage imageNamed:@"txweibo"];
cell.label.text = @"微信朋友圈";
cell.selectedBackgroundView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.25];
return cell;
}</span>
实现源码:FMGridView