Can we enable the cut copy paste menu for a
UILabel
as it is for aUITextField
?If not, and I need to convert my
UILabel
toUITextField
, how can I enable the cut copy paste menu and not allow the content to be modified?
views:
1201answers:
2
+2
A:
Override the UITextField
instance's textFieldShouldBeginEditing
method, and set it to return NO
in order to disable editing.
Take a look at the UITextFieldDelegate
protocol for more details.
Alex Reynolds
2009-08-07 19:01:22
The problem is: copy and paste won't work if you disable editing.
mrueg
2009-12-17 09:28:36
+1
A:
I got the copy & paste menu working on a UILabel
, I just had to return YES
for canBecomeFirstResponder
and later call [label becomeFirstResponder]
when the said label was to come on screen. As for returning YES
from canBecomeFirstResponder
, you can create a custom subclass or patch UILabel
using a category:
@implementation UILabel (Clipboard)
- (BOOL) canBecomeFirstResponder
{
return YES;
}
@end
The category solution feels a bit hackish, but if you know what you’re doing it might be easier than subclassing.
zoul
2010-04-16 13:55:28