
如何给collectionView的每一个cell添加一个测试数字,UITableView非常方便,提供了 TitleLabel.text 方法接口,UICollection没有这个方法。
我们自己使用UILabel去添加一个。
核心源码:
cell.backgroundColor = [UIColor colorWithWhite:234 / 255.0 alpha:0.5];
NSInteger tag = 100;
UILabel *lbl = [(UILabel *) cell.contentView viewWithTag:tag];
if( lbl == nil){
lbl = [[UILabel alloc] init];
lbl.tag = tag;
[cell.contentView addSubview:lbl];
lbl.frame = CGRectMake(0, 0, 24, 20);
lbl.center = CGPointMake(cell.bounds.size.width*0.5,cell.bounds.size.height*0.5);
lbl.textAlignment = NSTextAlignmentCenter;
}
lbl.text = [NSString stringWithFormat:@"%ld",indexPath.item];
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)