gpt4 book ai didi

iPhone UITableViewCell : repositioning the textLabel

转载 作者:行者123 更新时间:2023-12-03 18:13:32 25 4
gpt4 key购买 nike

我是 iPhone 开发新手,目前正在开发一个简单的 RSS 阅读器应用程序。我遇到的问题是我需要重新定位 UITableViewCells 内的 textLabel 。我尝试过 setFramesetCenter 但它没有做任何事情。有谁知道我需要在 tableView:cellForRowAtIndexPath: 方法中做什么才能将 textLabel 重新定位在单元格顶部(x = 0,y = 0)?

谢谢

PS:UITableViewCell 由名为 cell 的变量引用。我尝试了 [cell setFrame:CGRectMake(0, 0, 320, 20)] 但没有成功。

最佳答案

您可以为 UITableViewCell 创建子类并自定义 textLabel 框架。请参阅答案:Labels aligning in 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];
}

关于iPhone UITableViewCell : repositioning the textLabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2984994/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com