2017-05-31 33 views
1

我在用於行小區嘗試這種下面的代碼...如何爲cell.imageView.frame設置框架?

if([cell.textLabel.text isEqualToString:@"Home"]) 
    { 
     cell.imageView.image = [UIImage imageNamed:@"Home-50.png"]; 
cell.imageView.frame=CGRectMake(10, 15, 20, 20); 
} 

這是下面的代碼是在Indexpath didselect行...

if ([[arrCell objectAtIndex:indexPath.row] isEqualToString:@"Home"]) { 
    cell.imageView.image = [UIImage imageNamed:@"Home1-50.png"]; 
    cell.imageView.frame=CGRectMake(10, 15, 20, 20); 
} 

我用這上面的代碼來顯示圖像在tableview單元格和單元格單擊然後圖像更改爲另一圖像...圖像正在更改但幀,不適用...

+0

ImageView的 - 是默認ImageView的或定製的ImageView –

+0

更改中的任何標誌值select並重新加載tableview並更改單元格中的框在該標誌的索引路徑上行會更容易 –

+0

[cell.imageView layoutifNeed];在調整幀大小之後放置這個 –

回答

1

不,你不能這樣做,因爲它是固定佈局的UITableViewCell.If你想要做到這一點下面的選項

OPTION 1:CustomCell

Through CustomCell you can set image view frame whatever you want. 

選項2:編程方式創建圖像視圖將其添加到細胞

UIImageView *img = [[UIImageView alloc] init]; 
img.image = [UIImage imageNamed:@"yourImageName.png"]; 
[img setFrame:CGRectMake(10, 15, 20, 20)]; 
[[cell.contentView addSubview:img];];