2013-08-28 81 views
0

我想知道如何動態地設置一個tableview單元格的圖像視圖的中心。如何在tableview單元格上動態設置imageview中心

這是我目前的代碼。

UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(100,100, 20, 20)]; 


imgView.image = [UIImage imageNamed:@"friendsCelluserpic.png"]; 


cell.imageView.image = imgView.image; 
+0

使用單元格的寬度和高度,然後抵消它的圖像的大小? – mdoran3844

+0

我很困惑請告訴我更多關於你的答案。謝謝 –

+0

imageView.center = CGPointMake(cell.contentView.bounds.size.width/2,cell.contentView.bounds.size.height/2); – Jitendra

回答

0

,你可以像這樣的代碼[cell.contentView addSubview:imgView];

+0

其工作完美,然後我想設置我的單元格顏色灰色,以及如何可以在導航壩上添加圖像? –

+0

使用此代碼:'cell.backgroundView = [UIView new]; cell.backgroundView.backgroundColor = [UIColor yellowColor];' –

1

試試這個代碼: 這將調整圖像水平中心TableViewCell

float imgwidth=40; 
    float imgheight=40; 

    imgView = [[[UIImageView alloc] initWithFrame:CGRectMake((cell.contentView.bounds.size.width/2)-(imgwidth/2),15, imgwidth, imgheight)] autorelease]; 

    [cell.contentView addSubview:imgView]; 
+0

爲我工作!感謝Mahesh –

1

試試這個,:)

UIImageView * imgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"friendsCelluserpic.png"]]; 
imgView.frame=CGRectMake(100, 100, 20, 20); 

[cell.contentView addSubview:imgView]; 
return cell; 
相關問題