Fire Fist
Fire Fist

Reputation: 7050

UITableViewCell's footer text in iOS

I want to do like following pic.

enter image description here

How can i do to use like that?

Is that following method?

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section

Thanks.

Upvotes: 2

Views: 5491

Answers (2)

spaceMonkey
spaceMonkey

Reputation: 4615

I would rather put this in viewDidLoad() or else it would create sort of a floating effect, which i don't prefer. here is my solution in swift

    let footerView = UIView(frame:CGRectMake(0,0,self.view.frame.size.width,30))
    footerView.backgroundColor = UIColor.clearColor()
    let footerLabel = UILabel(frame: footerView.frame)
    footerLabel.textColor = UIColor.flatGrayColor()
    footerLabel.textAlignment = NSTextAlignment.Center
    footerView.addSubview(footerLabel)
    footerLabel.text="\(self.items.count) Items";
    self.tableView.tableFooterView=footerView

Upvotes: 2

T0m_Twt
T0m_Twt

Reputation: 623

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *footer = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 540, 10)];
    footer.backgroundColor = [UIColor clearColor];

    UILabel *lbl = [[UILabel alloc]initWithFrame:footer.frame];
    lbl.backgroundColor = [UIColor clearColor];
    lbl.text = @"Your Text";
    lbl.textAlignment = NSTextAlignmentCenter;
    [footer addSubview:lbl];

    return footer;
}


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

Upvotes: 7

Related Questions