6

I have a label with the text @"Good,Morning"

I want to find the position(x,y) of letter ","(Comma) in the label.

Can anyone tell & Suggest me that how to find this..

Toseef Khilji
  • 17,192
  • 12
  • 80
  • 121
surendher
  • 1,374
  • 3
  • 26
  • 52
  • read @lemnar's answer in this post.http://stackoverflow.com/questions/6808974/uilabel-get-cgrect-for-substring-of-text – Mani Dec 18 '13 at 06:01
  • Have a look at the following links: [First Link][1], [Second Link][2] [1]: http://stackoverflow.com/questions/3191049/finding-location-of-specific-characters-in-uilabel-on-iphone [2]: http://stackoverflow.com/questions/13654766/add-uigesturerecognizer-to-individual-letters-of-uilabel – Shad Dec 18 '13 at 06:07
  • This cannot be done with `UILabel` as per this Q&A: [find the location {x,y} of text in uilabel](http://stackoverflow.com/questions/9273889/find-the-location-x-y-of-text-in-uilabel). Read the answer to that question for a workaround – Amar Dec 18 '13 at 06:11
  • have you tried this?, http://stackoverflow.com/a/9274048/2629258 – sathiamoorthy Dec 18 '13 at 07:52

1 Answers1

5

Try this code.

NSRange range = [@"Good,Morning" rangeOfString:@","];
NSString *prefix = [@"Good,Morning" substringToIndex:range.location];
CGSize size = [prefix sizeWithFont:[UIFont systemFontOfSize:18]];
CGPoint p = CGPointMake(size.width, 0);
NSLog(@"p.x: %f",p.x);
NSLog(@"p.y: %f",p.y);

Hope this will help you.

sathiamoorthy
  • 1,488
  • 1
  • 13
  • 23