How can I add an image with coordinates in the UIView? - iphone

Is it possible to add an image in the UIView with specific coordinates?
If so, anyone who is keen on explaining how to?

You need to create an UIImageView and set it's frame to the desired coordinate.
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:<#imageName#>]];
imageView.frame = CGRectMake(<#x#>, <#y#>, <#width#>, <#height#>);
[yourViewController.view addSubView:imageView];
Let me know if this works for you.

Something like this?
UIImageView *myImage = [[UIImageView alloc] initWithImage:someImage];
myImage.frame = CGRectMake(40, 40, myImage.frame.size.width, myImage.frame.size.height);
[myView addSubview:myImage];
That'll add an image, contained in an image view, at specific coordinates.

Yes, you have either to draw the image in -(void)drawRect:(CGRect)aRect;, by subclassing UIView, or to add an UIImageView as a subview of the main view, displaying the image.
Have a look on these :
UIImageView Class Reference.
UIView

Related

I want to get imageView Position vertically upside down

In the Below image there are two imageViews one is body imageView and another one is black tattoo imageview ,
Now i am getting the tatoo imageView position with the below code
appDelegate.xFloat= self.imgView.frame.origin.x;
appDelegate.yFloat= self.imgView.frame.origin.y;
appDelegate.widthFloat= self.imgView.frame.size.width;
appDelegate.heightFloat= self.imgView.frame.size.height;
Now i need to put the tattoo image in another view controller as we are seeing in the image(Here Car is in reverse position), But with the help of (appDelegate.xFloat, appDelegate.yFloat, appDelegate.widthFloat, appDelegate.heightFloat) these I am setting the tattooimageview frame.
But i am getting the image as shown below in another view
I need to place the car image in reverse as we seen in first image.
Please Guide Me
My requirement is not only rotation.. The image may be in any position like below
It is strange that one image is not rotating and the other one is rotating. I am assuming that one of the images is a background image or what ever, but you can use transform properties to change the rotation. Some thing similar to the code below should show you the same image in two orientations.
UIImage *image = [UIImage imageNamed:#"image.png"];
UIImageView *iv1 =[[UIImageView alloc] initWithImage:image];
[self.view addSubview:iv1];
UIImageView *iv2 = [[UIImageView alloc] initWithImage:image];
[iv2 setFrame:CGRectMake(100,100,image.size.width,image.size.height)];
[iv2 setTransform:CGAffineTransformMakeRotation(-M_PI)];
[self.view addSubview:iv2];
you must contructor appDelegate before use it.
by:
appDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
Babul, Looks like you are trying to create an image. For that you need to use some thing called ImageContext. I have given some code, where you draw an image in a context and then get the image out.
UIGraphicsBeginImageContext(CGSizeMake(300,300));
UIImage *image = [UIImage imageNamed:#"breakpoint place.png"];
[image drawAtPoint:CGPointMake(0,0)];
UIImage *image2 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *iv = [[UIImageView alloc] initWithImage:image2];
[iv setFrame:CGRectMake(100,100,image2.size.width,image2.size.height)];
[self.view addSubview:iv];

How to fill the part of the imageview with another color

I am developing an application in which I am using one UIImageView and adding one rectangle image to that UIImageView. I am getting some float value from another calculation like 67.4 and I need to place one green image on the 67.4 part of rectangle UIImageView. So please tell me how can I fill that green image onto that UIImageView ?
You can make a "rectangle", i.e. a UIView and color it as you wish. Then add it to your image view.
UIView *greenRect = [[UIView alloc] initWithFrame:
CGRectMake(67.4, 67.4, width, height)];
greenRect.backgroundColor = [UIColor greenColor];
[imageView addSubview:greenRect];

how can I use UIImageView on full screen in UIViewController?

I am developing a software and in it I am making a new file, which is subclass of UIViewController, when I do use UIImageView, then there is little border remaining in it, what should I do so that my image should cover all area around it,
my coding of UIImageView in ViewDidLoad is
UIImageView* view = [[UIImageView alloc] initWithImage: [UIImage imageNamed: #"frontnew.png"]];
view.frame = CGRectMake(0, 0, 320, 415);
[self.view addSubview:view];
now what should I do ????
If I increase height and width then it will increase from two sides, not all ???
you should set imageview property as scalltoFit
May be it can help you

iPhone: Mask UIImageView of differing dimensions into square dimension

I have a bunch of UIImageViews that are in different proportions. Some of 100x101 some are 130x121.
How can I mask these to 80x80 and NOT stretch the images? I basically just want to mask a square out of each one. (kind of like the Apple's Photo thumbnail view does)
Set the image view's size to 80 x 80
set the image view's contentMode property to UIViewContentModeScaleAspectFill
Finally, to make round corners, use the following code, and import QuartzCore/QuartzCore.h at the beginning of your implementation file.
CALayer * layer = [myImageView layer];
[layer setMasksToBounds:YES];
[layer setCornerRadius:12.0f];
Edited: Yes, by saying size I mean frame, the W and H:
Set its content mode UIViewContentMode, you may be looking for UIViewContentModeScaleAspectFit or UIViewContentModeScaleAspectFill.
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 80, 80)];
[imageView setContentMode:UIViewContentModeScaleAspectFit];
[imageView setImage:[UIImage imageNamed:#"myImage.png"];
.
.
.

Load dynamic Image in tableHeaderView

I want to add a dynamic image in the UITableView's tableHeaderView part.
For that i am writing following code :
UIImageView *myImageView = [[UIImageView alloc]initWithFrame: CGRectMake(0.0f,
0.0f,
320.0f,
44.0f)];
self.tableView.tableHeaderView = myImageView;
[myImageView release];
With this code i am getting image in my screen, but with stretched view.
Now i want to set that image at the particular corner of HeaderView of table.
Anyone have any solution then please help me..
Thanks in advance..
Add your UIImageView to a regular container UIView and place it inside that.