我有一个自定义的TableView看起来像下面的图片如何设置基于图像可用性的TextField帧的UITableViewCell
我的想法是tableview
第四行中没有image
那个时候我想将label
frame
左边等于image
左边我该怎么做?
我有一个自定义的TableView看起来像下面的图片如何设置基于图像可用性的TextField帧的UITableViewCell
我的想法是tableview
第四行中没有image
那个时候我想将label
frame
左边等于image
左边我该怎么做?
如果你希望你的标签上相同的左坐标,你可以使用代码的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;
}
}
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
}
}
此方法将设置与imageview相同的标签框架,这实际上不是正确的答案。他只想将标签的左侧坐标设置为与imageView的左侧坐标相同。 –
是的,这实际上是他想要做的。但是@chirag Bhutani在你面前增加了正确的答案,所以我投了赞成票。无论如何,thanx纠正它。希望你能以你的经验帮助社区。 Gud luck –
@SKM欢迎光临,如果你有自定义单元格然后属性合成所有控件,然后在cellForRaw方法中设置框架..我在我的许多应用程序中做这种类型的代码.. –
这实际上应该做什么。正确答案 –
感谢您的回答,但我有小pbm我正在使用自定义的uitableviewcell我设置框架在drawRect函数内,因此框架值不能在cellForRowAtIndexPath函数中更改如何解决此问题 – Ben10
如果您正在使用自定义函数,在这种情况下,您应该将x坐标作为参数发送到函数中,并相应地设置帧的x坐标。 –