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