Link to home
Start Free TrialLog in
Avatar of TWB_Systems
TWB_Systems

asked on

Get the top left coordinates of a UITextView

I have a UITextView that is a part of scrollView..  What I want to do is get the top left coordinates of the TextView when the user clicks a button.  Can this be accomplished?

Thanks,
Matt
ASKER CERTIFIED SOLUTION
Avatar of pgnatyuk
pgnatyuk
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In order to avoid misunderstanding: myView in the previous comment is the scrollView from your question, it does not change its position and so the bounds and the size do not change.
Avatar of TWB_Systems
TWB_Systems

ASKER

Thanks for your reply... Do you have convert rect.origin.y to an integer? It keeps returning 0 for me when I try to display with NSLog("Y is: %i", rect.origin.y);
If it's float, print it as float: %f.
NSLog("Y is: %f", rect.origin.y);

If you need it as int, cast it same way as in C: (int), for example:
NSLog("Y is: %i", (int)(rect.origin.y));

This origin is NSPoint, it is a structure, but knows how to "explain itself" with NSStringFromPoint(thePoint).
So you can use:
NSLog(@"Origin %@", NSStringFromPoint(rect.origin));

It is not a correct way to ask the related question, please don't do it this way.

Thanks for your help!

I used the following:

CGRect rect = [scrollView bounds];
NSLog(@"My y is: %f", rect.origin.y);
You are welcome.
I thought you work on Mac and so said about NSRect and about NSStringFromPoint. :)
So please mention it next time and I will not confuse you in my comments.

Best regards