iOS 7上的cell.imageView.image和indentationLevel

时间:2013-09-20 09:11:27

标签: objective-c uitableview tableview ios7

如何使图像与文本之间的距离更近? 在ios 6中,相同的代码正常显示,但在新版本的距离增加。

我通过标准方法做任何事情

[cell.textLabel setText: .....

// cell.indentationLevel = 0; // this is for test

UIImage * img = [UIImage imageNamed: @ "image10.png"];
             NSData * imageData = UIImagePNGRepresentation (img);
            cell.imageView.image = [UIImage imageWithData: imageData];

附图 https://www.dropbox.com/s/lt119xgozvzzstd/image01.png

1 个答案:

答案 0 :(得分:0)

如果我没记错的话,缩进级别只影响文本。因此,当您更改缩进级别/宽度时,实际上是在更改imageViewtextLabel之间的距离。

我对此进行了测试,遗憾的是您不能使indentationWidth为负。因此,您需要继承UITableViewCell并使用您自己的视图进行设置(我建议在故事板中进行设置,使用自动布局并将indentation设置为NSLayoutConstraint以便您在您的单元格indentationConstant上有一个属性,例如您可以更改的属性。我这样做的目的略有不同,我需要缩进整个contentView。没有办法在Storyboard中继承子类和创建自定义视图,抱歉。 (我甚至不会建议一些可怕的黑客访问子视图和修改他们的框架,今天一切都是自动布局。)