gpt4 book ai didi

ios - UITableViewCell 标签不需要的缩进

转载 作者:行者123 更新时间:2023-12-01 18:56:53 25 4
gpt4 key购买 nike

我刚刚更新了一个 Objective-C iOS 应用程序以使用"new"的 iOS 8 Storyboard。更新所有约束后,我注意到在滚动时,一些标题标签(自定义单元格)似乎缩进,这不是我想要他们做的。当我改变滚动方向时,它似乎总是发生,但我不完全确定如何重现它。我不知道在哪里寻找解决方案,但我很确定它与约束没有任何关系。下面是一些细胞的图片。前两个缩进正确,后两个没有。

我能做些什么来防止这种缩进?

Indented cell labels

最佳答案

在您的 cellForRowAtIndexPath方法,您可以改为在单元格上添加一个标签,作为带有自定义文本的 subview 。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] init];
}

UILabel *title = [[UILabel alloc] init];
title.text = @"my text";
title.frame = CGRectMake(0,0,desiredWidth,rowHeight); // setting the origin at (0,0) should position the label over that indentation you don't want
[titleview addSubview:title];

return cell;
}

关于ios - UITableViewCell 标签不需要的缩进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26237245/

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