0
这里是我的代码的UILabel添加到特定indexpath在UICollectionView
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return 10;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
CollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"dfdsfs" forIndexPath:indexPath];
if (indexPath.item == 0) {
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 100, 50)];
label.text=[NSString stringWithFormat:@"this is item %ld", (long)indexPath.item];
[cell.contentView addSubview:label];
cell.contentView.backgroundColor = [UIColor greenColor];
NSLog(@"im @ zero");
} else {
NSLog(@"im here %ld", (long)indexPath.item);
cell.contentView.backgroundColor = [UIColor yellowColor];
}
return cell;
}
我想只有索引路径零添加标签。作为标签出现在其他指数路径还 我得到的问题..
感谢您的回复 –
@SunilKumar不客气!它有用吗?如果是 - 请接受我的回答。 – ppalancica