gpt4 book ai didi

iphone - 如何使用 UITextAlignment 将 UITableViewCell 中的文本在 Swift 中左右对齐

转载 作者:行者123 更新时间:2023-11-28 10:02:45 24 4
gpt4 key购买 nike

我必须将表格单元格中的文本左右对齐。我在我的应用程序中使用了两个 plist根据 plist 选择,我必须在表格单元格中对齐我的文本。

我尝试使用下面的代码

if ([app.currentPlist isEqualToString:@"Accounting.plist"]) {
cell.textAlignment=UITextAlignmentLeft;
} else {
cell.textAlignment=UITextAlignmentRight;
}

最佳答案

UITableViewCell 没有 textAlignment 属性。您必须在单元格的文本标签上设置它:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row = [indexPath row];

static NSString *CellIdentifier = @"Cell";

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

cell.textLabel.text = @"Something";

if([app.currentPlist isEqualToString:@"Accounting.plist"])
{
cell.textLabel.textAlignment=UITextAlignmentLeft;
}
else
{
cell.textLabel.textAlignment=UITextAlignmentRight;
}

return cell;
}

关于iphone - 如何使用 UITextAlignment 将 UITableViewCell 中的文本在 Swift 中左右对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7162126/

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