开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜