ios - Objective C Subclass UITextField to copy only -
i'm trying create class makes read text field allows user copy contents. here code:
copyonly.h
#import <uikit/uikit.h> @interface copyonly : uitextfield @end
copyonly.m
#import "copyonly.h" @implementation copyonly - (id)initwithframe:(cgrect)frame { self = [super initwithframe:frame]; if (self) { // initialization code [self attachtaphandler]; } return self; } - (void) attachtaphandler { [self setuserinteractionenabled:yes]; uigesturerecognizer *touchy = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(handletap:)]; [self addgesturerecognizer:touchy]; } - (bool) canperformaction: (sel) action withsender: (id) sender { return (action == @selector(copy:)); } - (void) handletap: (uigesturerecognizer*) recognizer { [self becomefirstresponder]; uimenucontroller *menu = [uimenucontroller sharedmenucontroller]; [menu settargetrect:self.frame inview:self.superview]; [menu setmenuvisible:yes animated:yes]; } - (void)copy:(id)sender { uipasteboard *board = [uipasteboard generalpasteboard]; [board setstring:self.text]; self.highlighted = no; [self resignfirstresponder]; } - (bool) canbecomefirstresponder { return yes; } @end
this works great, keyboard coming up. don't want keyboard come up.
i tried adding initwithframe:
uiview* nokeyboard = [[uiview alloc] initwithframe:cgrectmake(0, 0, 1, 1)]; self.inputview = nokeyboard;
this not give me result i'm expecting. know how can this?
extending on comment. accomplished using uitextview
(not uitextfield
) editable
property set no
.
uitextview* tf = [[uitextview alloc] initwithframe:cgrectmake(50, 50, 200, 50)]; tf.editable = no; tf.text = @"hey test!"; [self.view addsubview:tf];
Comments
Post a Comment