Mayank
Mayank

Reputation: 1139

Blue coloured Footer in UITableView for an iPhone Native App in Objective C

I am developing an iPhone App using X-Code in objective C. I want to add a blue coloured footer (same as header) at the bottom of the table.

Can anyone help me in suggesting How this can be achieved. Also How to add a button in this footer.

Thanks in advance.

enter image description here

Upvotes: 0

Views: 572

Answers (5)

Vidya Murthy
Vidya Murthy

Reputation: 530

You can create a custom view with the components you want (UIButton, UIImageView, etc) and set the required values in -(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section

Or you could just assign the same view to tableFooterView

tableView.tableFooterView = yourBlueView;

Upvotes: 0

NSUserDefault
NSUserDefault

Reputation: 1834

Hope this will help you

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *viewFotter = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 44)];
    [viewFotter setBackgroundColor:[UIColor blueColor]];
    return viewFotter;
}

But the thing is, u can't resize the button.Because it's doesn't worked for me.

Upvotes: 2

Paras Joshi
Paras Joshi

Reputation: 20541

paste this code in your .m file also you can add image in your footerview

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 44;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *viewFotter = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 44)];
    [viewFotter setBackgroundColor:[UIColor blueColor]];
    UIButton *GoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [GoBtn setTitle:@"GO" forState:UIControlStateNormal];
    GoBtn.frame = CGRectMake(85, 7, 150, 39 );
    [GoBtn addTarget:self action:@selector(GOButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [viewFotter addSubview:GoBtn];
    return viewFotter;
}

Upvotes: 1

NSUserDefault
NSUserDefault

Reputation: 1834

You can add the button by just dragging the UIButton to the footer of the UITableView in xib.But you can't resize the button as it will automatically assigns to the table view's width. But I don't understand what you are saying regarding footer color.Can you pls elaborate it.

Upvotes: 0

Nookaraju
Nookaraju

Reputation: 1668

 - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 40;
  }

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
            UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
            footerView.backgroundColor =[UIColor blueColor];
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            [btn setTitle:@"BUTTON" forState:UIControlStateNormal];
            btn.frame = CGRectMake(100, 5, 100, 30 );
            [btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
            [footerView addSubview:btn];
            return footerView;
    }

   -(void) btnClicked:(id) sender{
     //ur code
    }

Upvotes: 1

Related Questions