Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Get the top left coordinates of a UITextView

Posted on 2010-08-15
6
Medium Priority
?
986 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 33

Accepted Solution

by:
pgnatyuk earned 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Industry Leaders: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops 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.

730 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