开发者

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

开发者 https://www.devze.com 2023-03-20 20:06 出处:网络
Is it possible to add an image in the UI开发者_运维问答View 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 desir

Is it possible to add an image in the UI开发者_运维问答View 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

0

精彩评论

暂无评论...
验证码 换一张
取 消