2012-11-16 18 views

回答

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; 
    } 
} 
+1

这实际上应该做什么。正确答案 –

+0

感谢您的回答,但我有小pbm我正在使用自定义的uitableviewcell我设置框架在drawRect函数内,因此框架值不能在cellForRowAtIndexPath函数中更改如何解决此问题 – Ben10

+0

如果您正在使用自定义函数,在这种情况下,您应该将x坐标作为参数发送到函数中,并相应地设置帧的x坐标。 –

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 
    } 
} 
+0

此方法将设置与imageview相同的标签框架,这实际上不是正确的答案。他只想将标签的左侧坐标设置为与imageView的左侧坐标相同。 –

+0

是的,这实际上是他想要做的。但是@chirag Bhutani在你面前增加了正确的答案,所以我投了赞成票。无论如何,thanx纠正它。希望你能以你的经验帮助社区。 Gud luck –

+0

@SKM欢迎光临,如果你有自定义单元格然后属性合成所有控件,然后在cellForRaw方法中设置框架..我在我的许多应用程序中做这种类型的代码.. –

相关问题