subtitle alignment in UITableViewCell

cocoa-touch, uilabel, uitableview

Solution

Ok so subclass UITableView Cell and customize the labels with init. You can override layoutSubviews and move the labels to the right:

- (void)layoutSubviews {
    [super layoutSubviews];
    self.textLabel.frame = CGRectMake(0.0, 68.0, 80.0, self.frame.size.height);
    self.detailTextLabel.frame = CGRectMake(0.0, 68.0, 120.0, self.frame.size.height);
}

These are just example values so you can get the idea.

Problem

i`m trying to build a table view with subtitle text in cells the problem is when i try to set the alignment of the subtitle text to the right it doesn't work, but it works fine with the main text here is my code ``` - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"CustomCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; } [[cell textLabel] setTextAlignment:UITextAlignmentRight]; [[cell detailTextLabel] setTextAlignment:UITextAlignmentRight]; cell.textLabel.text = [array objectAtIndex:indexPath.row]; cell.textLabel.font = [UIFont systemFontOfSize:18]; cell.detailTextLabel.text = @"test"; return cell; } ``` when i remove the subtitle code the alignment works fine any idea ?

Original source