Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align text in UITableView's Footer

I'm using

- (NSString *)tableView:(UITableView *)tv titleForFooterInSection:(NSInteger)section
{
if (section == 1)
{
    return @
    "Some text  \r\n"
    "\r\n"
    "1. Point 1\r\n "
    "2. Point 2\r\n"
    "3. Point 3";
}
    return @"";
}

for the footer of a group of cells. It works great, but I want to align the text to the left (to help the look). I know you can create a view / UILabel using viewForFooterInSection but it seems an ugly work around. Is there any way to align it?

like image 850
daihovey Avatar asked Mar 01 '11 04:03

daihovey


2 Answers

tableView:viewForFooterInSection: is not a workaround.

It's common for Apple to give you two options, the easy way and the manual way.

If the easy way (tableView:titleForFooterInSection:) isn't doing what you want, you have the ultimate in flexibility by adding your own view.

In fact, you can just return a UILabel in tableView:viewForFooterInSection:

Should be super easy.

like image 87
amattn Avatar answered Nov 01 '22 08:11

amattn


if your tableview is short, then you can also write something like this:

-(void)viewDidLayoutSubviews 
{
    for (int section = 0; section < [self.tableView numberOfSections]; section++)
    {
        [self.tableView footerViewForSection:section].textLabel.textAlignment = NSTextAlignmentRight;
    }
}
like image 4
Ardavan Kalhori Avatar answered Nov 01 '22 08:11

Ardavan Kalhori