How to keep a stronger reference of a UIImageView? - ios

the problem is that the image i want to show fist stays in the middle of the screen during the entire scrolling proccess obscuring the rest of the views contents. Any fixes ? My storyboard had a UIScrollView > list view and over it a UIImage connected to IBOutlets. Here is the rest of the code. Thanks.
UIImageView * imageView = [[UIImageView alloc]init];
[imageView setImage:[UIImage imageNamed:#"pcat3.png"]];
[imageView setFrame:CGRectMake(10,10,300,300)];
[imageView setContentMode:UIViewContentModeScaleToFill];
[imageView setUserInteractionEnabled:TRUE];
[self->listView addSubview:imageView];

Related

ImageView with same size of View(full screen) - Objective C

How to do programmatically ImageView with same size of View in a way that there is no difference between devices ?
UIImageView *imgV =[[UIImageView alloc] initWithFrame:self.view.frame];
imgV.image=[UIImage imageNamed:#"draw.png"];
[self.view addSubview:imgV];
suppose draw.png is xx size then draw#2x = 2(xx), draw#x = 3(x*x)
please supply image draw.png, draw#2x.png , draw#3x.png in resource
hope it help
With code you can create a UIImageView with giving the frame of superview.
UIImageView* myImageView = [[UIImageView alloc]initWithFrame:self.view.frame];
[myImageView setImage:[UIImage imageNamed:#"yourImage.jpg"]];
[self.view addSubview:myImageView];
By Autolayout using storyboards we can do like this.
Drag an UIImageView to the view and provide these constraints and add.

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.)

Rotated imageview not appearing after addsubview

I have added an arrow image view and I want to rotate it to create a corner.
My code is pretty simple:
[self.view addSubview:self.upLeftCorner];
self.upLeftCorner.transform = CGAffineTransformMakeRotation(2.35619449);
The imageview appears when i don't rotate it, however it does not after the rotation. I tried adding the subview after the rotation but still it does not appear. Any help?
Well, this is working:
UIImage *image = [UIImage imageNamed:#"image.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[imageView setFrame:CGRectMake(0, 0, 100, 100)];
imageView.transform = CGAffineTransformMakeRotation(2.35619449);
[self.view addSubview:imageView];
I think its because you did the addSubview before rotating the imageView. In my code, I rotated then addSubview

Unable to center a UIImage in a UIScrollView

I have the following code in ViewDidLoad of my UiTableViewController:
UIImage *noImage = [UIImage imageWithContentsOfFile:pathOfNoImageFile];
UIImageView *imageview = [[UIImageView alloc] initWithImage:noImage];
[imageview setContentMode:UIViewContentModeScaleAspectFit];
imageview.frame = workingFrame;
[self.scrollview addSubview:imageview];
workingFrame.origin.x = workingFrame.origin.x + workingFrame.size.width;
[self.scrollview setPagingEnabled:YES];
[self.scrollview setContentSize:
CGSizeMake(workingFrame.origin.x,workingFrame.size.height)];
I therefore am only able to see the image partially and have attached a screen shot.
What can i do to fix it? I have Googled and looked at several Stack Overflow questions but have not been able to have it work. Please suggest. I have a scrollview in the uitableviewcell. I need to center my image vertically .
Your scrollview/cell size will need to be big enough to hold the imageview that you want to display. Looks like one or both is too small so I would adjust your sizes accordingly.

Place an UIImageView behind the tableView in a UITableViewController Subclass

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"]];

Resources