Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 994
  • 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?

Thanks,
Matt
0
TWB_Systems
Asked:
TWB_Systems
  • 4
  • 2
1 Solution
 
pgnatyukCommented:
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
http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/NSScrollViewGuide/Articles/Scrolling.html

0
 
pgnatyukCommented:
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.
0
 
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);
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
pgnatyukCommented:
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.

0
 
TWB_SystemsAuthor Commented:
Thanks for your help!

I used the following:

CGRect rect = [scrollView bounds];
NSLog(@"My y is: %f", rect.origin.y);
0
 
pgnatyukCommented:
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
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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