2

Possible Duplicate:
Enable copy and paste on UITextField without making it editable

I need to disable editing on UITextField but keep the copy/paste function

when i use

textField.enabled = NO;

then function copy/paste is disabled;

textField.editing = NO;

Xcode write "Assigning to property with 'readonly' attribute not allowed

Community
  • 1
  • 1

1 Answers1

0

You can find the help here :

This is subclass of UILabel, you can do exactly similar with UITextField. And Change the class from UITextField to this one.

@implementation CopyableLabel


- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
    if(action == @selector(copy:)) {
        return YES;
    }
    else {
        return [super canPerformAction:action withSender:sender];
    }
}


- (BOOL)canBecomeFirstResponder {
    return YES;
}


- (BOOL)becomeFirstResponder {
    if([super becomeFirstResponder]) {
        self.highlighted = YES;
        return YES;
    }
    return NO;
}


- (void)copy:(id)sender {
    UIPasteboard *board = [UIPasteboard generalPasteboard];
    [board setString:self.text];
    self.highlighted = NO;
    [self resignFirstResponder];
}


- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    if([self isFirstResponder]) {
        self.highlighted = NO;
        UIMenuController *menu = [UIMenuController sharedMenuController];
        [menu setMenuVisible:NO animated:YES];
        [menu update];
        [self resignFirstResponder];
    }
    else if([self becomeFirstResponder]) {
        UIMenuController *menu = [UIMenuController sharedMenuController];
        [menu setTargetRect:self.bounds inView:self];
        [menu setMenuVisible:YES animated:YES];
    }
}


@end
Community
  • 1
  • 1
Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140