---
title: "ios  UITableViewCell  文字缩进 "
author: "ynial"
date: "2011-12-02T12:00:46Z"
tags: []
categories: ["移动开发"]
slug: "ios-uitableviewcell"
draft: false
lastmod: "2011-12-02T12:00:46Z"
id: 1289299
url: "https://ynial.iteye.com/blog/1289299"
---

【前提】
  
  UITableViewCell 原本就有他自己的imageView ，希望在这个imageView上再添加一个icon，
  
  textLabel要缩进 icon 寛的大小。


 【解决方案】

  
```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; //每次缩进寛
  
```


   这种办法即能显示出原本的背景图片 也能显示出icon 同时也解决了 icon和textLabel重叠显示的问题。使用文本缩进动态调整他x轴的位置。