2013-10-17 132 views
2

以下是我從一個應用程序採取從App Store中的形象:我創建了一個使用故事板自定義的tableview細胞的應用UITableViewCell的自定義圖像大小,陰影和邊框

UITableViewCell

。數據從Web服務中加載。這是我想要的:

1)如何根據圖像更改uitableviewcell的大小?例如,如果一個圖像是640 * 500,那麼UITableViewCell將相應地改變其大小。如果圖像的大小是640 * 1000,則單元格應相應地更改其大小。

2)如何在桌面視圖單元周圍添加灰色邊框,就像上圖中一樣?

3)如何添加陰影從UITableViewCell滴下就像在上面的圖像?

謝謝!

回答

1

目前我有一個部分回答你的問題。在所述彩色邊框可以通過下面的代碼來解決的問題的第2部分:

[cell.contentView.layer setBorderColor:[UIColor colorWithRed:222/255.0f green:222/255.0f blue:222/255.0f alpha:1.0f].CGColor]; 
[cell.contentView.layer setBorderWidth:5.0f]; 
0

部分-1 使用確定tableviewcell的高度

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    /* 
    Get the image size 
    CGFloat width = myImage.size.width; 
    CGFloat height = myImage.size.height; 
    use this to return the height of your cell. 
    */ 
} 

部分-2和本部3 使用..

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { 

    //This will give you access to the cell being rendered and any customization you want can be done here... You can use the earlier answer for this part.. I havent tried it but should work.. 
} 

希望這有助於..

+0

我是否需要改變首先UIImageView的大小,然後單元格的高度? – AJ112

+0

返回考慮到UIImageView大小的高度,然後您可以在cellForRowAtIndexPath中手動設置UIImageView的框架 – Sharath