我有这段代码来获取“。”之间的文本。例如,我有很多文本,例如 .1 这是第一个。2 这是第二个。3 这是第四个等等。当我点击第一个分机时,它会在日志中显示第一个文本。代码是
- (void)textViewDidBeginEditing:(UITextView *)textView
{
[NSTimer scheduledTimerWithTimeInterval:0.001 target:maintextview selector:@selector(resignFirstResponder) userInfo:nil repeats:NO];
}
- (void)textViewDidEndEditing:(UITextView *)textView
{
NSRange selectedRange = [textView selectedRange];
NSString *backString = [maintextview.text substringToIndex:selectedRange.location];
NSRange backRange = [backString rangeOfString:@"." options:NSBackwardsSearch];
NSRange backRangee = [backString rangeOfString:@"." options:NSBackwardsSearch];
int myRangeLenght = backRangee.location - backRange.location;
NSRange myStringRange = NSMakeRange (backRange.location, myRangeLenght);
NSString *forwardString = [maintextview.text substringFromIndex:backRange.location];
NSLog(@"%@",[[forwardString componentsSeparatedByString:@"."] objectAtIndex:1]);
}
forwadString 包含点击的文本,我只想突出显示该字符串或使用核心图形或类似的东西在该文本上方绘制颜色。可能吗?提前致谢