在tableview单元格iphone中移动文本

时间:2020-12-13 10:44:07

I have table view cells with cell image and text label and detailed label. Problem is cell image is too near to edge of cell(to the left). I want to put some space between edge and cell image. i.e. wants to move image bit away from corner. I have moved that with creating subview and putting image in that. But problem is it now overcome cell text and detailed text as well. I want to move cell text and detailed label to the right as well.

我有表视图单元格,包含单元格图像和文本标签以及详细标签。问题是细胞图像太靠近细胞边缘(向左)。我想在边缘和细胞图像之间放一些空格。即想要将图像位从角落移开。我已经移动了创建子视图并将图像放入其中。但问题是它现在也克服了细胞文本和详细文本。我想将单元格文本和详细标签也移动到右侧。

How can i do that?

我怎样才能做到这一点?

For moving cell image, i am using below code:

对于移动细胞图像,我使用下面的代码:

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

But i want to move text and detailed text label as well.

但我想移动文本和详细的文本标签。

1 个解决方案

#1


1  

You don't need that image view to move the image.

您不需要该图像视图来移动图像。

Subclass UITableViewCell and add the following method to the subclass:

子类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;
}

Change 10 to whatever you see fit.

将10更改为您认为合适的任何内容。

#1


1  

You don't need that image view to move the image.

您不需要该图像视图来移动图像。

Subclass UITableViewCell and add the following method to the subclass:

子类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;
}

Change 10 to whatever you see fit.

将10更改为您认为合适的任何内容。