简体   繁体   English

如何在 UIView 中添加带有坐标的图像?

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

Is it possible to add an image in the UIView with specific coordinates?是否可以在 UIView 中添加具有特定坐标的图像? 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 并将其框架设置为所需的坐标。

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;是的,您必须在-(void)drawRect:(CGRect)aRect;中绘制图像。 , by subclassing UIView , or to add an UIImageView as a subview of the main view, displaying the image. ,通过UIView ,或者添加一个UIImageView作为主视图的子视图,显示图像。

Have a look on these:看看这些:

UIImageView Class Reference . UIImageView Class 参考
UIView UIView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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