Say I have an array of strings I am displaying the following data in a tableView:
Rank Name Item
The first field is consistant length (4), however the middle field is variable so what I would love to be able to do is somehow split the cell so that Item is right justified. Is there an easy way to do this?
Rank Name Item
So
Sarg Bobmarley magic
Capt Huf axe
Peon Yumkru sword
Becomes
Sarg Bobmarley magic
Capt Huf axe
Peon Yumkru sword
Cell method:
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
TableViewPracticeAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
cell.textLabel.text = [[appDelegate theArray] objectAtIndex:indexPath.row];
cell.textLabel.font = [UIFont boldSystemFontOfSize:15];
}
Any thoughts or ideas appricated!
You have to make a custom cell. There’s no NSAttributedString in iOS (Update: iOS6 brings NSAttributedString). Its simple really, here’s an example: