我跟在我所加入的標籤的圖像上,同樣在Facebook上,展現在集合視圖圖像當我們點擊在收集圖像iOS應用程序工作在Facebook中,它擴展了它的圖像並用標籤顯示圖像。不同的圖像大小在大小上顯示不同。我也是這樣做。一切工作正常,但是當我加入小圖片它改變標籤對細胞的位置。它意味着出現在大圖像的兩個標籤,一個標籤正是我想要和第二小的圖像標籤。我正在處理這段代碼:在不同的位置上UICollectionView小區追加標籤的iOS
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
int i;
Cell *cell;
UILabel * lblName ;
UILabel * lblName1 ;
cell=[collectionView dequeueReusableCellWithReuseIdentifier:REUSEABLE_CELL_IDENTITY forIndexPath:indexPath];
@try
{
NSLog(@"index path is %ld",(long)indexPath.row);
if(rearr.count == 0)
{
cell.imageviews.image=NULL;
}
else
{
NSLog(@"count %lu",(unsigned long)rearr.count);
for (i=0;i<rearr.count; i++)
{
NSLog(@"count %lu",(unsigned long)rearr.count);
image = [UIImage imageWithContentsOfFile:rearr[i]];
NSLog(@"image.size.width1 : %f",image.size.width);
NSLog(@"image.size.height1 : %f",image.size.height);
if(image.size.width > image.size.height)
{
lblName = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 230.0, 300.0,80)];
lblName.text = @"Image";
lblName.textAlignment = NSTextAlignmentCenter;
[lblName setFont:[UIFont fontWithName:@"GothamRounded-Bold" size:10]];
[lblName setTextColor:[UIColor colorWithRed:137.0f/255.0 green:137.0f/255.0 blue:137.0f/255.0 alpha:1.0]];
[lblName setBackgroundColor:[UIColor whiteColor]];
[cell.contentView addSubview:lblName];
}
else
{
lblName1 = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 410.0, 300.0,80)];
lblName1.text = @"Image1";
lblName1.textAlignment = NSTextAlignmentCenter;
[lblName1 setFont:[UIFont fontWithName:@"GothamRounded-Bold" size:10]];
[lblName1 setTextColor:[UIColor colorWithRed:137.0f/255.0 green:137.0f/255.0 blue:137.0f/255.0 alpha:1.0]];
[lblName1 setBackgroundColor:[UIColor whiteColor]];
[cell.contentView addSubview:lblName1];
}
if(image != nil)
{
[itms addObject:image];
}
else
{
NSData *data = [[NSData alloc]initWithContentsOfFile:rearr[i]];
image=[UIImage imageWithData:data];
[itms addObject:image];
}
}
cell.imageviews.image=[itms objectAtIndex:indexPath.row];
cell.imageviews.layer.cornerRadius=5.0f;
cell.imageviews.clipsToBounds = YES;
}
return cell;
}
@catch (NSException *exception)
{
NSLog(@"image insertion in collecvcontroller : exception %@",exception);
return cell;
}
}
請幫我一把。我不知道我做錯了什麼。
這將是更好的,如果你提供的問題得到更好的主意的屏幕截圖。 – Mrunal