gpt4 book ai didi

ios - 将 UITableViewCell 中的文本右对齐

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:59:37 26 4
gpt4 key购买 nike

我需要将单元格中的文本右对齐。

但即使我设置为右侧,文本也会向左对齐,如屏幕截图所示知道为什么细胞会出现这种奇怪的行为

cell.textLabel.textAlignment = NSTextAlignmentRight;
cell.detailTextLabel.textAlignment = NSTextAlignmentRight;

在stackoverflow上阅读了相关问题和答案后,我找不到解决我问题的方法

enter image description here

最佳答案

No不能改变Cell的titleLabel的frame。相反,您可以将自定义标签添加到单元格的 contentView。

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * cellIdentifier = @"Cell";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

if (cell==nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];

UILabel *lblStatus = [[UILabel alloc] initWithFrame:CGRectMake(12, 8, 175, 15)];
lblStatus.backgroundColor = [UIColor clearColor];
[lblStatus setTag:101];
[cell.contentView addSubview:lblStatus];

}
UILabel *lbl1 = (UILabel *)[cell.contentView viewWithTag:101];
lbl1.text=@"set text";
}
return cell;
}

您也可以通过原型(prototype)单元实现这一点。 here is a good tutorial of prototype cell.

关于ios - 将 UITableViewCell 中的文本右对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26710892/

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