简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM