ho creato un campo di testo in una classe BBCustomUtility.h, file di classe .m e poiDisabilita copia, incolla nel UITextField non funziona in iOS 9.x
+(UITextField*)createTextField: (CGRect)rect image:(NSString*)imageName tag:(int)tag secureText:(BOOL)entry placeh:(NSString*)placeholder
{
UITextField *transactionField = [ [ UITextField alloc ] initWithFrame: rect ];
transactionField.background = [UIImage imageNamed:imageName];
transactionField.adjustsFontSizeToFitWidth = YES;
transactionField.textColor = [UIColor blackColor];
transactionField.font = [UIFont systemFontOfSize:17.0];
transactionField.placeholder = placeholder;
transactionField.backgroundColor = [UIColor clearColor];
transactionField.borderStyle = UITextBorderStyleNone;
transactionField.autocorrectionType = UITextAutocorrectionTypeNo;
transactionField.autocapitalizationType = UITextAutocapitalizationTypeNone;
transactionField.textAlignment = UITextAlignmentCenter;
transactionField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
transactionField.keyboardType = UIKeyboardTypeDefault;
transactionField.returnKeyType = UIReturnKeyDone;
transactionField.tag = tag;
transactionField.delegate = self;
transactionField.clearButtonMode = UITextFieldViewModeWhileEditing;
transactionField.text = @"";
[ transactionField setEnabled: YES ];
transactionField.secureTextEntry = entry;
return transactionField ;
}
importazione da classe comune e utilizzato in Class1 .m
mPasswordField1 = [BBCustomUtility createTextField:CGRectMake(IS_WIDTH_DEVICE/2-120, 140, 50, 50) image:@"txtField_bg_50.png" tag:1 secureText:YES placeh:[shareObj.mLabelDictionary valueForKey:@""]];
mPasswordField1.keyboardType = UIKeyboardTypeNumberPad;
mPasswordField1.clearButtonMode = UITextFieldViewModeNever;
mPasswordField1.delegate = self;
[self.view addSubview:mPasswordField1];
provato a disabilitare l'opzione copia incolla sul campo di testo nei metodi indicati questi non stanno lavorando per me
1)
-(BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
// Returning 'NO' here disables all actions on textfield
return NO;
} // not working still showing the paste option on textfield
2)
-(BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == @selector(copy:) || action == @selector(paste:)) {
return NO;
}
return [super canPerformAction:action withSender:sender];
} // this is also not working still showing the paste option
3)
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if ([mPasswordField1 respondsToSelector:@selector(inputAssistantItem)])
{
UITextInputAssistantItem *inputAssistantItem = [mPasswordField1 inputAssistantItem];
inputAssistantItem.leadingBarButtonGroups = @[];
inputAssistantItem.trailingBarButtonGroups = @[];
}
} // this also not working
uno può dirmi qual è l'errore che ho fatto nel mio codice.
Grazie per aver lavorato per me. – Balu
Prego ... :) – Lion
Al momento sto votando ma non è bello chiedere una domanda di voto secondo le linee guida di stacdkoverflow. – Lion