0

我有一个自定义的 TableView 如下图所示

我的表视图

我的想法是在tableview第四行没有image那个时候我想将label frame左边设置为等于image左边我该怎么做?

4

2 回答 2

2

如果您希望您的标签与 imageView 位于相同的左坐标上,您可以使用以下代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    // do the below code after setting the image in your imageView. 

    if (imageView.image == nil) 
    {
        CGRect rectNew = CGRectMake(imageView.frame.origin.x, cell.textLabel.frame.origin.y, cell.textLabel.frame.size.width, cell.textLabel.frame.size.height);
        cell.textLabel.frame = rectNew;
    }
}
于 2012-11-16T07:35:59.447 回答
1

cellForRowAtIndexPath:方法中,如果图像为零,则将 imageView 的框架设置为cell.textLable. 如下所示。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {  
    if (imageView.image == nil) {
        imageView.hidden = YES;
            cell.textLabel.frame = CGRectMake(imageView.frame.origin.x, imageView.frame.origin.y, setWidth, setHight);//set Hight and width of yout textlable of cell
    }
}
于 2012-11-16T07:07:25.120 回答