我試圖讓單元格文本與表格視圖的左側齊平。我試着設置tableView.contentInset = UIEdgeInsetsMake(-4,-8,0,0),它對滾動視圖很好,但對於tableView,內容仍然顯示在右側。使單元格內容顯示與UITableView的邊緣齊平
有沒有人知道我需要的內容與表視圖的邊緣齊平的確切數量,或者也許是一種不同的方式來做到這一點?
這就是我的意思(藍色字母是如何起飛的權利):
(^這是默認的contentInset)
我試圖讓單元格文本與表格視圖的左側齊平。我試着設置tableView.contentInset = UIEdgeInsetsMake(-4,-8,0,0),它對滾動視圖很好,但對於tableView,內容仍然顯示在右側。使單元格內容顯示與UITableView的邊緣齊平
有沒有人知道我需要的內容與表視圖的邊緣齊平的確切數量,或者也許是一種不同的方式來做到這一點?
這就是我的意思(藍色字母是如何起飛的權利):
(^這是默認的contentInset)
更改表視圖的contentInset ISN」正確的做法。細胞已經到了桌子的邊緣。你可以通過設置單元格的背景顏色來驗證這一點。默認情況下,單元格的textLabel
設置爲距離邊緣稍微有點距離。您應該嘗試調整單元格的框架textLabel
。對此最好的地方最有可能是tableView:willDisplayCell:forRowAtIndexPath:
委託方法。
另一種選擇是自定義表格視圖單元格,它將文本放在單元格內的位置,而不依賴於更改默認設置。
對我來說,最好的方法是創建一個實例UILabel變量,然後在您的cellForRow:AtIndexPath:方法中初始化UILabel。
您可以將框架定義爲任何你喜歡的。給它一個標籤號碼。
準備好之後,將UILabel作爲子視圖添加到您的cell.contentView。
// .h file
@interface MyClass
{
UILabel *lblCellText;
}
// .m file
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellID = @"cellID";
UITableViewCell *cell = [tableView dequeReusableCellWithID:cellID];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle.....];
// ------------------------------------
// initialise your UILabel here
// ------------------------------------
lblCellText = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, tableView.rowHeight)];
lblCellText.tag = 1;
[cell.contentView addSubview:lblCellText];
[lblCellText release];
}
// find your UILabel from the pool of dequed UITableViewCells
lblCellText = (UILabel *)[cell.contentView viewWithTag:1];
lblCellText.text = "New playlist";
return cell;
}