UITableViewCell 的 textLabel 与子视图标签重叠,我该如何解决?(iPhone 开发) [英] UITableViewCell's textLabel is overlapping a subview label, how can I fix it? (iPhone Dev)

查看:24
本文介绍了UITableViewCell 的 textLabel 与子视图标签重叠,我该如何解决?(iPhone 开发)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为后续:UITableViewCell 中的 UILabel 子视图是不露面(iPhone 开发)

我发现我作为子视图添加的 UILabel 正确显示和定位,但是当我设置单元格的 labelField 时,它似乎重叠"了我在子视图中添加的标签.

换句话说,bar"仅在我注释掉以下代码片段的第一行时显示:

<前><代码>cell.textLabel.text = @"foo"//子视图文本标签UILabel *valueField = (UILabel *)[cell viewWithTag:111];valueField.text = @"bar";

有没有办法让 cell.textLabel 不与同一行"上的 UILabel 重叠?也许通过调整cell.textLabel的底层框架?

这个问题似乎也只发生在我使用 SDK > 2.2.1 进行编译时,是否有一些更改会在 3.0 中对此产生影响?

谢谢

解决方案

UITableViewCell 的 textLabel 背景不清晰.我认为从你的自定义标签到这个的位置太小了,当默认的 textLabel 显示文本时,它的背景覆盖了你的自定义标签(条).

更改此消息中默认 textLabel 字段的背景颜色:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{[cell setBackgroundColor:[UIColor clearColor]];}

As a follow up to: UILabel subview in UITableViewCell isn't showing up. (iPhone Dev)

I have found out that the UILabel I added as a subview is showing up and positioned correctly, however when I set the cell's labelField, it seems to "overlap" the label I have added in the subview.

In other words "bar" only shows up when I comment out the first line of the following code snippet:


cell.textLabel.text = @"foo"
// sub view text label
UILabel *valueField = (UILabel *)[cell viewWithTag:111];
valueField.text = @"bar";

Is there a way to make the cell.textLabel not overlap the UILabel that's on the "same line"? maybe by adjusting the underlying frame of cell.textLabel?

This problem also seems to only occur when I'm compiling with an SDK > 2.2.1, did something change that would affect this in 3.0?

Thanks

解决方案

UITableViewCell´s textLabel has a non clear background. I think that the position from your custom label to this one is so tiny that when the default textLabel shows text, it´s background covers your custom label (bar).

Change the background color for the default textLabel field in this message:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    [cell setBackgroundColor:[UIColor clearColor]];
}

这篇关于UITableViewCell 的 textLabel 与子视图标签重叠,我该如何解决?(iPhone 开发)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆