【前提】
UITableViewCell 原本就有他自己的imageView ,希望在这个imageView上再添加一个icon,
textLabel要缩进 icon 寛的大小。
【解决方案】
<pre name="code" class="Objective-c">
UIImage *icon = [UIImage imageNamed:item.icon];
UIImageView *imgview = [[UIImageView alloc]initWithImage:icon];
imgview.frame = CGRectMake(5, 10, 15, 21);
[cell.contentView addSubview:imgview];
cell.indentationLevel = 2; //缩进层级
cell.indentationWidth = 10.0f; //每次缩进寛
</pre>
这种办法即能显示出原本的背景图片 也能显示出icon 同时也解决了 icon和textLabel重叠显示的问题。使用文本缩进动态调整他x轴的位置。
UITableViewCell 原本就有他自己的imageView ,希望在这个imageView上再添加一个icon,
textLabel要缩进 icon 寛的大小。
【解决方案】
<pre name="code" class="Objective-c">
UIImage *icon = [UIImage imageNamed:item.icon];
UIImageView *imgview = [[UIImageView alloc]initWithImage:icon];
imgview.frame = CGRectMake(5, 10, 15, 21);
[cell.contentView addSubview:imgview];
cell.indentationLevel = 2; //缩进层级
cell.indentationWidth = 10.0f; //每次缩进寛
</pre>
这种办法即能显示出原本的背景图片 也能显示出icon 同时也解决了 icon和textLabel重叠显示的问题。使用文本缩进动态调整他x轴的位置。

本文介绍如何在UITableViewCell的内置imageView上添加额外的icon,并通过调整textLabel的缩进层级和宽度来避免与icon重叠显示。该方法不仅能让背景图片与新增的icon同时显示,还能通过文本缩进动态调整textLabel的位置。
66

被折叠的 条评论
为什么被折叠?



