나는 컬렉션 뷰의 이미지를 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