Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get UIImage origin.x from UIImageVIew

Is it possible to get the X coordinate of a UIImage, that is displayed in a UIImageView when the view's scale mode is set to Center?

Image to better illustrate what I want:

Picture explaining the problem

like image 938
Gio Avatar asked Feb 18 '26 21:02

Gio


2 Answers

It's pretty much basic maths:

CGFloat x = (imageView.frame.size.width - imageView.image.size.width) / 2;

I think no.

But there is work around solution, you can calculate image height and width and according to that you can calculate centre position by (imageView.frame.size.width-image.size.width)/2 and same thing for height.

Hope this solves your issue.

like image 31
P.J Avatar answered Feb 21 '26 14:02

P.J