iPhone UITableViewCell:重新定位textLabel [英] iPhone UITableViewCell: repositioning the textLabel
问题描述
我是iPhone开发的新手,我目前正在开发一个简单的RSS阅读器应用程序。我遇到的问题是我需要在 UITableViewCells
中重新定位 textLabel
。我尝试了 setFrame
或 setCenter
但它没有做任何事情。有没有人知道我需要在 tableView:cellForRowAtIndexPath:
方法中重新定位顶部的 textLabel
。 cell(x = 0,y = 0)?
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)?
谢谢
PS: UITableViewCell
是由名为 cell
的变量引用。我试过 [cell setFrame:CGRectMake(0,0,320,20)]
但没有成功。
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中对齐。这对我来说很完美。
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.
这是我的子类
#import "UITableViewCellFixed.h"
@implementation UITableViewCellFixed
- (void) layoutSubviews {
[super layoutSubviews];
self.textLabel.frame = CGRectMake(0, 0, 320, 20);
}
@end
这是我的UITableViewControllerClass:
It's my UITableViewControllerClass:
UITableViewCellFixed *cell = (UITableViewCellFixed *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCellFixed alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
这篇关于iPhone UITableViewCell:重新定位textLabel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!