I'm trying to right align the text that is shown up in the table view section header from its datasource call viewForHeaderInSection using the following code but the text is still left aligned. I tried other alignment options but none worked. Can someone help me out please.
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UITableViewHeaderFooterView *headerView = [[UITableViewHeaderFooterView alloc] initWithFrame:CGRectMake(legendTableView.frame.origin.x, legendTableView.frame.origin.y, legendTableView.frame.size.width, 10)];
headerView.textLabel.textAlignment = NSTextAlignmentRight;
double total= 0;
for (Amount *amountObj in currentArray) {
total=total+[amountObj.amount doubleValue];
}
NSNumberFormatter *currencyFormatter = [[NSNumberFormatter alloc] init];
currencyFormatter.numberStyle = NSNumberFormatterCurrencyStyle;
NSString *amountString = [currencyFormatter stringFromNumber:[NSNumber numberWithDouble:total]];
NSString *totalString = [NSString stringWithFormat:@"Total: %@",amountString];
headerView.textLabel.text = totalString;
return headerView;
}
Thanks. Neerav