2014-05-12 104 views
0

我爲我的通用應用程序製作了自定義單元格。在iPhone屏幕文本是正常的,但當我移動到iPad屏幕文本從最左邊開始(如下圖所示)。我怎麼能把它移動一點(也許10px)。有沒有辦法從012px 方法中的10px開始文本標籤?提前致謝。UITableViewCell中的文本對齊

iPad UITableView Screen

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell2"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

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

    cell.textLabel.text = [firstArray objectAtIndex:indexPath.row]; 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    cell.textLabel.numberOfLines = 0; 
    [cell.textLabel setLineBreakMode:NSLineBreakByWordWrapping]; 


    UIImage *background = [self cellBackgroundForRowAtIndexPath:indexPath]; 

    cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, cell.bounds.size.width); 

    UIImageView *cellBackgroundView = [[UIImageView alloc] initWithImage:background]; 
    cellBackgroundView.image = background; 
    cell.backgroundView = cellBackgroundView; 

    return cell; 
} 
+0

你怎麼現在設置你的細胞?發佈一些如何創建自定義單元格的代碼 – Stonz2

回答

0

如果你想覆蓋該領域的文本插入,覆蓋「-editingRectForBounds:」

- (CGRect)editingRectForBounds:(CGRect)bounds { 
    return CGRectInset(bounds , 10 , 10); 
} 

如果要移動的標籤的單元格內,你可以創建自定義的UITableViewCell類並覆蓋佈局子視圖

- (void) layoutSubviews { 
    [super layoutSubviews]; 
    self.textLabel.frame = CGRectMake(10, 0, 310, 20); 
} 

該單元格可以初始化這樣

cell = [[YOUR_CUSTOM_CELL_CLASS alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 

編輯

在你的表視圖控制器:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    //Dequeue if possible of course 
    UITableViewCell *cell = [[CustomCellClass alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Identifier"]; 

    cell.textLabel.text = @"Should be indented"; 

    return cell; 
} 

在你CustomCellClass:

- (void) layoutSubviews { [super layoutSubviews]; self.textLabel.frame = CGRectMake(100, 0, 310, 20); }

然後文本標籤將縮進100分:)

來源: 只是沒有

+0

我創建了一個自定義單元類並覆蓋了layoutSubviews,但它不起作用。 –