How to find the position (x, y) of a letter in UILabel

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

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

Can anyone tell and suggest me how to find this.

+6
source share
1 answer

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(@"px: %f",px); NSLog(@"py: %f",py); 

Hope this helps you.

+5
source

All Articles