我是iPhone开发的新手,我正在开发一个简单的RSS阅读器应用程序。 我遇到的问题是我需要在UITableViewCells内重新定位textLabel 。 我已经尝试过setFrame或setCenter但它没有做任何事情。 有没有人知道我在tableView:cellForRowAtIndexPath:需要做什么tableView:cellForRowAtIndexPath:方法来重新定位单元格顶部的textLabel (x = 0,y = 0)?
谢谢
PS: UITableViewCell被称为cell的变量引用。 我试过[cell setFrame:CGRectMake(0, 0, 320, 20)]没有成功。
I am new to iPhone development and I am currently working on a simple RSS reader app. The problem I am having is that I need to reposition the textLabel inside the UITableViewCells. I have tried setFrame or setCenter but it doesn't do anything. Does anyone know what I need to do inside the tableView:cellForRowAtIndexPath: method to reposition the textLabel at the top of the cell (x = 0, y = 0)?
Thank you
PS: The UITableViewCell is referenced by a variable called cell. I have tried [cell setFrame:CGRectMake(0, 0, 320, 20)] with no success.
最满意答案
您可以为UITableViewCell创建一个子类,并自定义de textLabel框架。 看到这个答案: UITableViewCell中的标签对齐 。 这对我来说是完美的。
这是我的子类
#import "UITableViewCellFixed.h" @implementation UITableViewCellFixed - (void) layoutSubviews { [super layoutSubviews]; self.textLabel.frame = CGRectMake(0, 0, 320, 20); } @end这是我的UITableViewControllerClass:
UITableViewCellFixed *cell = (UITableViewCellFixed *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCellFixed alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; }You can create a subclass for UITableViewCell and customize de textLabel frame. See that answer: Labels aligning in UITableViewCell. It's works perfectly to me.
It's my subclass
#import "UITableViewCellFixed.h" @implementation UITableViewCellFixed - (void) layoutSubviews { [super layoutSubviews]; self.textLabel.frame = CGRectMake(0, 0, 320, 20); } @endIt's my UITableViewControllerClass:
UITableViewCellFixed *cell = (UITableViewCellFixed *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCellFixed alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; }更多推荐
发布评论