ITeye博客

ios UITableViewCell 文字缩进

ynial · 2011-12-02 12:00 · 移动开发 · Markdown

【前提】

UITableViewCell 原本就有他自己的imageView ,希望在这个imageView上再添加一个icon,

textLabel要缩进 icon 寛的大小。

【解决方案】


        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; //每次缩进寛
  

这种办法即能显示出原本的背景图片 也能显示出icon 同时也解决了 icon和textLabel重叠显示的问题。使用文本缩进动态调整他x轴的位置。

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。