2009-07-22 105 views
1

我有一個包含左側圖像的標準UITableViewCells的UITableView。我設置單元格的圖像如下:在OS 3.0中更改UITableViewCell中左側UIImageView的位置

UIImage *leftIcon = [UIImage imageNamed:@"myImage.png"]; 
cell.imageView.image = leftIcon; 

這工作正常。但是,外觀有所不同,具體取決於App運行的iPhone OS。在2.2.1之前,圖像距離左邊界約11個像素。在3.0中,圖像直接位於左邊界上,沒有任何空間。

我的目標是在3.0的單元格左側放置圖像大約11px。我想沒有任何成功以下幾點:

UIImage *leftIcon = [UIImage imageNamed:@"myImage.png"]; 

//trying to change x coordinate of the frame of the UIImageView 
CGRect tmpRect = cell.imageView.frame; 
tmpRect.origin.x = 10; 
cell.imageView.frame = tmpRect; 

cell.imageView.image = leftIcon; 

我能想到的兩種可能的解決方案:

1)執行我的自定義的UITableViewCell在左側的自定義的UIImageView。

2)添加11像素透明邊框使用Photoshop :)

任何建議myImage.png?

回答

0

在我看來,你可以做的最簡單的事情來解決iPhone世界中的這樣的問題是創建自定義類。另外,還要考慮每個自定義類創建一些函數表示類,如

-(void)redrawAtDefaultCoordinates; 
-(void)redrawAtCoordinates(NSInteger x, NSInteger y); 

,這樣就可以簡單地進行調整,它們顯示在哪裏。

至於你的實際問題,我會說試圖找到單元格使用的矩形,然後找出你需要的相對幾何。 iPhone在你想要放置物品的位置猜測時做得相當不錯,但如果猜測錯誤,你總是至少需要一些東西。

1

這有點破解,但你可以從你的UITableViewDelegate縮進你的單元格。

- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath { 
    return 1; 
} 

這將對推動了效果的UITableViewCell「約10點S. UIImageView

相關問題