0

This is my first iOS project, so I am learning a lot and have to learn more.

I learnt that in order to fit more items on UITableViewCell, I need to subclass it and then use it. I created TransactionCell and in my ViewController I use it as

- (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;
}  

Also, I set the height of cell as

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 100;
}

My xib looks like
enter image description here

When I run the project however, I see the following

enter image description here

Things don't fit up!

Question
- How do I make the labels appear completely on TransactionCell?
- How do I fit all the elements in a single row without cutting off

I am sure I need to learn something else, but not sure what

rmaddy
  • 314,917
  • 42
  • 532
  • 579
daydreamer
  • 87,243
  • 191
  • 450
  • 722

3 Answers3

0

While your label is selected in the xib, go to the autoshrink section in the attributes inspector and change the option to minimum font scale, I usually set it to around 0.5.

Jacob
  • 2,338
  • 2
  • 22
  • 39
0

Add three separate UILabel inside the cell and set the frame for three different size.

Apple
  • 121
  • 2
  • 12
-1

As @Shadowfiend told,you have to work with the auto layout and auto resizing.

Check this link: http://www.appcoda.com/self-sizing-cells/

It is nice tutorial on auto resizing the cells and well described too.

Hope it help.

Hiren
  • 676
  • 7
  • 21