这是我的第一个iOS
项目,因此我学到了很多东西并且需要了解更多。
我了解到为了在UITableViewCell
上放置更多项目,我需要对其进行子类化然后再使用它。我创建了TransactionCell
,在我的ViewController
中,我将其用作
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// make last cell visible: http://stackoverflow.com/questions/11928085/uitableview-not-visible-the-last-cell-when-scroll-down
tableView.contentInset = UIEdgeInsetsMake(0, 0, 120, 0);
[tableView registerNib:[UINib nibWithNibName:@"TransactionCell" bundle:nil] forCellReuseIdentifier:CellIdentifier];
TransactionCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[TransactionCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
TransactionModel *transactionModel = self.transactionsModel.transactions[(NSUInteger) indexPath.row];
cell.dateAndMonth.text = transactionModel.date;
cell.name.text = transactionModel.name;
cell.amount.text = transactionModel.amount;
cell.categoryImage.image = [self getShortImage:[UIImage imageNamed:transactionModel.category]];
cell.transactionTypeImage.image = [self getShortImage:[UIImage imageNamed:@"Debit"]];
cell.imageView.contentMode = UIViewContentModeCenter;
return cell;
}
另外,我将单元格的高度设置为
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 100;
}
我的xib
看起来像是
当我运行项目时,我看到以下
事情不合适!
问题
- 如何使标签完全显示在TransactionCell
上?
- 如何在不中断
我确信我需要学习别的东西,但不确定是什么
答案 0 :(得分:0)
在xib中选择了标签后,转到属性检查器中的自动收缩部分,将选项更改为最小字体比例,我通常将其设置为0.5左右。
答案 1 :(得分:0)
在单元格内添加三个单独的UILabel,并将框架设置为三种不同的大小。
答案 2 :(得分:-1)
正如@Shadowfiend所说,你必须使用自动布局和自动调整大小。
点击此链接:http://www.appcoda.com/self-sizing-cells/
这是关于自动调整单元格大小的好教程,也很好描述。
希望有所帮助。