iPhone UITableViewCell:重新定位textLabel(iPhone UITableViewCell: repositioning the textLabel)

编程入门 行业动态 更新时间:2024-10-27 05:33:59
iPhone UITableViewCell:重新定位textLabel(iPhone UITableViewCell: repositioning the textLabel)

我是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); } @end

It's my UITableViewControllerClass:

UITableViewCellFixed *cell = (UITableViewCellFixed *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCellFixed alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; }

更多推荐

本文发布于:2023-08-01 04:16:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1352927.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:UITableViewCell   iPhone   repositioning   textLabel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!