2011-11-02 48 views
0

我有表格視圖單元格與單元格圖像和文本標籤和詳細的標籤。 問題是細胞圖像太靠近細胞邊緣(在左邊)。我想在邊緣和細胞圖像之間留出一些空間。即想要將圖像移離角落。我已經通過創建子視圖並將圖像置於其中。但問題是它現在克服了單元格文本和詳細文本。我想要將單元格文本和詳細標籤移動到右側。在tableview單元格中移動文本iphone

我該怎麼做?

對於運動細胞圖像,我使用下面的代碼:

UIImageView *imageview=[UIImageView alloc]]init]; 
imageView.frame=CGRectMake(10,0,40,40); 
[[cell.contentView]addsubview:imageView]; 

,但我想移動文本和詳細的文字標籤爲好。

回答

1

您不需要該圖像視圖來移動圖像。

子類UITableViewCell和下面的方法添加到子類:

- (void)layoutSubviews { 
    [super layoutSubviews]; 

    CGRect imageFrame = self.imageView.frame; 
    imageFrame.origin.x += 10; 
    self.imageView.frame = imageFrame; 

    CGRect textFrame = self.textLabel.frame; 
    textFrame.origin.x += 10; 
    self.textLabel.frame = textFrame; 

    CGRect detailTextFrame = self.detailTextLabel.frame; 
    detailTextFrame.origin.x += 10; 
    self.detailTextLabel.frame = detailTextFrame; 
} 

變化10任何你認爲合適的。

+0

你可以解釋我怎麼能子類uitableViewCell – Mann

+0

'@interface YourTableViewCell:UITableViewCell' –

+0

什麼是x在這裏?它說結構cgrect中沒有名爲'x'的成員? – Mann

相關問題