2014-09-05 52 views
0

這是我的第一個iOS項目,所以我學到了很多東西,需要學習更多。iOS:如何在UITableViewCell中嵌入UILabel文本?

我瞭解到,爲了適應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看起來像
enter image description here

當我運行該項目然而,我看到以下內容

enter image description here

事情不適合!

問題
- 怎樣使標籤完全出現在TransactionCell
- 如何適應單行所有元素,而無需切斷

我相信,我需要學習別的東西,但不知道什麼

+0

更改Interface Builder中標籤的大小。 – 2014-09-05 01:07:14

+0

嘗試過,但沒有解決它 – daydreamer 2014-09-05 01:10:13

+1

有太多的方法來實現這一點,自動佈局自動調整大小,一個非常大的主題 – meim 2014-09-05 01:11:37

回答

0

雖然在廈門國際銀行中選擇您的標籤,去屬性檢查器中的autoshrink部分並將選項更改爲最小字體比例,我通常將其設置爲大約0.5。

0

在單元格內添加三個單獨的UILabel並將框架設置爲三種不同的尺寸。

-1

正如@Shadowfiend所說,你必須使用自動佈局和自動調整大小。

檢查此鏈接:http://www.appcoda.com/self-sizing-cells/

這是對汽車很好的教程調整細胞,也很好的描述。

希望它有幫助。

相關問題