Điều này phù hợp với tôi.
Subclass UILabel và ghi đè lên các phương pháp:
- (BOOL)canBecomeFirstResponder {
return YES;
}
- (BOOL)canPerformAction:(SEL)action
withSender:(id)sender
{
return (action == @selector(copy:));
}
- (void)copy:(id)sender {
[[UIPasteboard generalPasteboard] setString:self.text];
}
Thêm Gesture vào nhãn của bạn để phát hiện máy.
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(LongPressDetected:)];
[_messageLabel addGestureRecognizer:longPress];
Xử lý sự kiện cử chỉ, trình bày một UIMenuController với khung mong muốn:
- (void)LongPressDetected:(UILongPressGestureRecognizer*)gesture {
[_messageLabel becomeFirstResponder];
[[UIMenuController sharedMenuController] setTargetRect:_messageLabel.bounds inView:_messageLabel];
[[UIMenuController sharedMenuController] setMenuVisible:YES animated:NO];
}
UILabel trở thành một responder đầu tiên? Bạn muốn phản hồi điều gì? – kennytm
Nó kế thừa từ UIResponder để nó có khả năng. – Ben
Tôi đang sử dụng thư viện của ai đó thực hiện công cụ khi một đối tượng có thuộc tính nhất định trở thành người trả lời đầu tiên. Nó cũng gửi tin nhắn cho người trả lời đầu tiên. Tôi tình cờ muốn gắn tất cả điều này vào nhãn của tôi. –