Solved

Get the top left coordinates of a UITextView

Posted on 2010-08-15
6
965 Views
Last Modified: 2013-11-25
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
Comment
Question by:TWB_Systems
  • 4
  • 2
6 Comments
 
LVL 33

Accepted Solution

by:
pgnatyuk earned 500 total points
ID: 33443215
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
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33443247
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
 

Author Comment

by:TWB_Systems
ID: 33445024
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 Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33445156
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
 

Author Comment

by:TWB_Systems
ID: 33447400
Thanks for your help!

I used the following:

CGRect rect = [scrollView bounds];
NSLog(@"My y is: %f", rect.origin.y);
0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 33447481
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now