user3373798
user3373798

Reputation: 81

How to add image bottom of the tableview in iOS

I want to add image on bottom of the tableview. But it should not scroll along with tableview

Please anybody have idea please share.

I am trying as follows

UIImage *img = [UIImage imageNamed:@"image.png"];
UIImageView *imgView = [[UIImageView alloc]initWithImage:img];
imgView.frame = CGRectMake(0, 0, img.size.width, img.size.height);
CGRect frame = imgView.frame;
frame.origin.x = 0;
frame.origin.y = self.tableView.frame.size.height - img.size.height;
imgView.frame = frame;
imgView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
[self.view addSubview:imgView];

But it is scrolling along with tableview

Upvotes: 0

Views: 1693

Answers (4)

Sarim Sidd
Sarim Sidd

Reputation: 2176

You can use setTableFooterView method of `UITableview, to set a view at the bottom of the table view.

Swift:

self.tableView.tableFooterView = UIImageView(image: myImageView)

Objective-C:

[[self tableView] setTableFooterView:[self myImageview]];  

Hope this helps

Upvotes: 2

mohitdream4u
mohitdream4u

Reputation: 166

change in your code

frame.origin.y = self.tableView.frame.size.height + self.tableView.frame.origin.y;

Upvotes: 0

bvsss
bvsss

Reputation: 72

    - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIImage *myImage = [UIImage imageNamed:@"bluebar.png"];
UIImageView *imageView = [[[UIImageView alloc] initWithImage:myImage] autorelease];
imageView.frame = CGRectMake(10,10,300,100);
return imageView;
}

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

U can add your image to the footer.

OR

U can create a cell and add image image to that custom cell and attach that cell to footer

Upvotes: 0

Michael Dautermann
Michael Dautermann

Reputation: 89519

Just add an image ON TOP of the table, not within the table (or as a "footer" view)

You can do it like this in your storyboard or XIB file:

image view is above the table view

Upvotes: 1

Related Questions