• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 995
  • Last Modified:

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?

  • 4
  • 2
1 Solution
use bounds:
NSRect rect = [myView bounds];
then rect.origin is the origin point (on Mac this is left-bottom corner). This rect contains the size. Add the height to the y.

In case you need:
Scrolling the Document View

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.
TWB_SystemsAuthor Commented:
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);
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

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.

TWB_SystemsAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now