定位UITableViewCell的imageView [英] Positioning the imageView of a UITableViewCell

查看:143
本文介绍了定位UITableViewCell的imageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在UITableView的每个UITableViewCell中,我在其imageView中放置一个图像。但是,如果我使用tableView:heightForRowAtIndexPath:增加一个单元格的高度,以便容纳更多的文本,我发现:

In every UITableViewCell of a UITableView I'm placing an image in its imageView. However, if I increase the height of a cell using tableView:heightForRowAtIndexPath: to accomodate more text, I've found that:



  1. 图片的左边距增加。

我想要的文字图像要垂直顶部对齐,以便它在单元格的左上角(像下面图像中的第一个单元格),并且没有增加左边距(因此,文本的左边距在第二单元格与第一单元格中的文本对齐)。

I'd like the image to be top-aligned vertically, so that it is in the upper-left corner of the cell (like the first cell in the image below) and not have its left margin increased (so that the left margin of the text in the second cell aligns with the text in the first cell).

更改imageView的框架,中心等似乎没有任何影响。有任何想法吗?谢谢...

Altering the frame, center, etc. of the imageView seems to have no affect. Any ideas? Thanks...

(我有一个问题的图片,但是SO不会让我发布图片,因为我是一个noob,信誉不到10 。Grrr ...)

(I have an image of the problem, but SO won't let me post an image yet because I'm a noob with less than 10 reputation. Grrr...)

推荐答案

您需要子类化UITableViewCell并覆盖layoutSubviews,如下所示:

You need to subclass UITableViewCell and override layoutSubviews, as follows:

- (void) layoutSubviews
{   
    [super layoutSubviews];

    self.imageView.frame = CGRectMake( 10, 10, 50, 50 ); // your positioning here
}



在您的cellForRowAtIndexPath:方法中,您的新单元格类型的实例。

In your cellForRowAtIndexPath: method, be sure to return an instance of your new cell type.

这篇关于定位UITableViewCell的imageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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