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

2020-02-29 00:40发布

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

1条回答
再贱就再见
2楼-- · 2020-02-29 01:42

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.

查看更多
登录 后发表回答