触摸时可点击文字不敏感,需要留一会儿才能触发该事件。有没有办法解决这个问题?
答案 0 :(得分:0)
从我们在评论中的讨论中,我相信您要求一种方法来使String的一部分可点击。为此,您可以使用NSAttributeString
和UITextView
来解决您的问题。
NSString *myString = @"Sample string - click";
NSMutableAttributedString *myAttributedString = [[NSMutableAttributedString alloc] initWithString:myString];
[myAttributedString addAttribute:NSLinkAttributeName value:[NSURL URLWithString:@"randomString"] range:[initString rangeOfString:@"click"]];
UITextView *myNonEditableTextView = [[UITextView alloc] initWithFrame:CGRectMake(60, 200, [[UIScreen mainScreen] bounds].size.width - 120, 100)];
myNonEditableTextView.delegate = self;
myNonEditableTextView.attributedText = myAttributedString;
myNonEditableTextView.editable = NO;
[self.view addSubview: myNonEditableTextView];
// delegate functions for UITextView
// - For versions >= iOS 10, this delegate function should be used
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange interaction:(UITextItemInteraction)interaction {
[self performAction];
return NO;
}
// - For versions < iOS 10, this delegate function should be used
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange {
[self performAction];
return NO;
}
希望这有帮助:)并告诉我你是否需要一个快速版本。