Reputation: 2487
I have a rather simple question about TableView's in iOS, is there a way to indent the contents of the cells in a tableview, say for example I have an array of strings, and I want to have them displayed on the ui as alternating series of text, it would look like a conversation log. eg.
I am Hercules
I am Delilah
If you are Delilah
Then I am your lover
This without resorting to custom cells, however, if the custom cells is the only, can you please show me how/where to start?
TIA
mirage
Upvotes: 0
Views: 131
Reputation: 22592
Within your cellForRowAtIndexPath
method, do something such as this:
if (indexPath.row % 2 == 0) {
[cell.textLabel setTextAlignment:UITextAlignmentLeft];
} else {
[cell.textLabel setTextAlignment:UITextAlignmentRight];
}
Updated with correct alignment, thanks paul polo
Upvotes: 2
Reputation: 1176
You can hook up when creating a cell in tableView : (UITableView *)tableView cellForRowAtIndexPath
method:
indexPath
whether you are creating odd or even cell.And you're done!
Upvotes: 0