Place an UIImageView behind the tableView in a UITableViewController Subclass - uitableview

I am trying to place a UIImageView behind a the tableView in a view controller that is a subclass of UITableViewController. I have gotten the following code to sort of work, but the image scrolls with the rows in the table.
UIImageView *backgroundView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[backgroundView setImage:[UIImage imageNamed:#"woodbackground1"]];
[self.view addSubview:backgroundView];
[self.view sendSubviewToBack:backgroundView];
[self.tableView setBackgroundColor:[UIColor clearColor]];
I tried the suggestions in this post
Add UIView behind UITableView in UITableViewController code but they produce the same result, am image that across with the table.
Is there a way to place the image view behind the tableview so that the image does not move with the table?
Thanks,
Dan

Why not use
self.tableView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"background"]];

Related

How can I make a TableView push an above object out of the way when scrolling up?

i.e. There is an object with specific data above a TableView, and when the TableView is scrolled up, I want the object above to be pushed off screen. Similar to the Maps app when you're looking at a business page, where there's the header, and then a TableView below with the phone, homepage, etc below.
Thanks!
There are many ways to achieve this.
1- Make the object with specific data above the tableview TableView
Header. From the question it look like you need help for that also so here how you will do it.
-(void)viewDidLoad
{
// ...
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(XXX, YYY, XXX, YYY)];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(XXX, YYY, XXX, YYY)];
[headerView addSubview:imageView];
UILabel *labelView = [[UILabel alloc] initWithFrame:CGRectMake(XXX, YYY, XXX, YYY)];
[headerView addSubview:labelView];
self.tableView.tableHeaderView = headerView;
[imageView release];
[labelView release];
[headerView release];
// ...
}
2- Implement scrollview delegate inside check if the scrollview is tableview then hide you object (view).

Background Image blocking my whole screen

I wanted to add a background image to my UIViewcontroller in my iOS app.
- (void)viewDidLoad {
[super viewDidLoad];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
[imageView setImage:[UIImage imageNamed:#"background"]];
[self.view addSubview:imageView];
}
This unfortunately produced a result where the whole screen was covered.
Is there a way to move this subview to the bottom layer so that it doesn't cover my buttons and textfields?
You need to insert the view at the bottom of the hierarchy
[self.view insertSubview:imageView atIndex:0];

How can I insert an imageView behind a UITableView in a fixed position (no scrolling)?

I am trying to insert an image behind my table view using:
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"newpink120"]];
imageView.frame=CGRectMake([[UIScreen mainScreen]bounds].size.width-60, [[UIScreen mainScreen]bounds].size.height-60-self.navigationController.navigationBar.frame.size.height, 60, 60);
[self.tableView addSubview:imageView];
[self.tableView sendSubviewToBack:imageView];
This seems to work but the image scrolls with the table. Is there anyway to keep it fixed in the bottom right corner?
For creating a static tableview background, you have to do 2 things
1) set self.tableView.backgroundColor = [UIColor clearColor];
2) and then initialise the table background view with an UIImageView and set the image you want to show there.
[self.tableView setBackgroundView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"image.png"]] ];
Your image scrolls because it has been added in the tableview content and when you scroll the tableview, all the content scrolls.
But you can add the image in the superview of your tableView, behind it.
For example, if the tableView is in self.view you can try :
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"newpink120"]];
imageView.frame=CGRectMake([[UIScreen mainScreen]bounds].size.width-60, [[UIScreen mainScreen]bounds].size.height-60-self.navigationController.navigationBar.frame.size.height, 60, 60);
[self.view addSubview:imageView];
[self.view bringSubviewToFront:self.tableView];
(Make sure that the tableView has a clear backgroundColor.)

ios to create view programmatically

I am trying to create a view like the below one programmatically but it covers the whole screen and does not be like this. There could be some thing size = Freeform, but could not find code on google to handle this.
UIView *picker = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 260)];
picker.backgroundColor = [UIColor whiteColor];
Actually I want to create this whole view programmatically not though interface Builder.
please help
No other way than CGRectMake
if you want create the UIView that covers the whole screen
UIView *picker = [[UIView alloc] initWithFrame:self.view.bounds];
picker.backgroundColor=[UIColor blueColor];
[self.view addSubview: picker];
if you want create the UIView that not covers the whole screen
UIView *picker = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 250, 260)];
picker.backgroundColor=[UIColor blueColor];
[self.view addSubview: picker];
Create UIToolBar which has UIBarButtonItem(=Done).
Set the UIToolBar as UIDatePicker's inputAccessoryView.
You don't even need a backgroundView to add Done button and date picker.

UIImageView shows outside its parents frame

I'm developing a iOs app for iPad and I'm implementing a UIImageView inside a UIView. The problem is that if the position of the image view has a position out of the UIView that it is inside, you can see it. The code:
UIView *vistafunda = [[UIView alloc] initWithFrame:CGRectMake(512/2, 48, 525, 651)];
[self.view addSubview:vistafunda];
vistafunda.backgroundColor = [UIColor darkGrayColor];
UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"hola.png"]];
img.center = CGPointMake(12, 200);
[vistafunda addSubview:img];
I would like that the image view was always under the view, so if the image is outside the view you could not see it.
Thanks!
Just make the containing view clip it's children
vistafunda.clipsToBounds = YES;

Resources