我想,这可能对你有帮助
// Create some text view for example
_tv = [[UITextView alloc] initWithFrame:CGRectMake(10.0, 10.0, 300.0f, 250.0f)];
_tv.text = @"dkjshfk shf kjhs fkj ewkjhf kwfwkj fhwk fwh fjkw hfjkhwe fkjwh";
_tv.font = [UIFont systemFontOfSize:24];
[self.view addSubview:_tv];
这就是你要找的
- (void)someAction:(id)sender
{
// Here is a frame of selected text in text view
CGRect frame = [_tv firstRectForRange:_tv.selectedTextRange];
// Mark selected text with yellow
UIView *v = [[[UIView alloc] initWithFrame:frame] autorelease];
v.backgroundColor = [UIColor yellowColor];
v.alpha = .8f;
[_tv addSubview:v];
}