2011-11-06 4 views
0

Я хочу разместить свое изображение в месте (10,10,60,60). Я пишу код, но отображаю изображение из угла. Код [cell.imageView setFrame:CGRectMake(10,10,60,60)]; не действует.imageView setFrame в виде таблицы

if(indexPath.row==0) 
{ 
    NSString *filepath=[[NSBundle mainBundle]pathForResource:pro.s_image ofType:@"png"]; 
    UIImage *image=[UIImage imageWithContentsOfFile:filepath]; 

    //cell.imageView.contentMode = UIViewContentModeScaleAspectFit; 

    //[cell.imageView setContentMode:UIViewContentModeScaleAspectFit]; 

    //[cell.imageView setFrame:CGRectMake(50,50,100,100)]; 

    [cell.imageView setFrame:CGRectMake(10,10,60,60)]; 

    // CGRect iframe = cell.imageView.frame; 
    // iframe.size.height = 100.0; 
    // iframe.size.width=100.0; 
    // cell.imageView.frame = iframe; 

    cell.imageView.image=image; 
} 

ответ

1

Один из вариантов заключается в подклассе UITableViewCell и определении местоположения изображения в подклассе.

Вот аналогичный пост за исключением они пытаются настроить расположение текстовой метки:

iPhone UITableViewCell: repositioning the textLabel

+0

@thanks bryanmac ..... я пытаюсь это сделать .... пожалуйста, дайте мне небольшое объяснение для - (void) layoutSubviews ... – GauravBoss

+0

@bryanmac ... спасибо ... моя программа вяжется нормально Теперь...:) – GauravBoss

0

Ленивый (плохо PRACTIVE) решение вместо подклассов к добавить UIImageView в клетки contentView (и игнорировать cell.imageView):

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    .... 
    UIImageView * myCreatedImageView=(UIImageView *)[cell.contentView viewWithTag:12345]; 
    if (myCreatedImageView==nil) { 
     myCreatedImageView=[[UIIimageView alloc]...] 
     myCreatedImageView.tag=12345;//identifying tag number 
     [self.contentView addSubview:myCreatedImageView]; 
    } 

    //code to manage the image view: 
    myCreatedImageView.frame=... 
    myCreatedImageView.image=... 
} 
0

Возможно, вы захотите попытаться переключить последние две строки. Как это:

cell.imageView.image=image; 
[cell.imageView setFrame:CGRectMake(10,10,60,60)]; 

cell.imageView может быть ноль, прежде чем предоставить изображение.

Смежные вопросы