ios objective-c uitextfield inputview

ios - Evite la edición de texto en UITextField y oculte el cursor/caret/lupa mientras usa un inputView



objective-c (6)

¿Cómo evito la edición de texto en un UITextField junto con ocultar el cursor / caret / lupa, pero todavía presento el teclado, ya que estoy utilizando un inputView con un UIPickerView / UIDatePickerView ?

La configuración de userInteractionEnabled en NO no funciona porque ya no recibe ningún toque y no presentará el teclado.


Encontré que la mejor solución era

- (CGRect) caretRectForPosition:(UITextPosition*) position { return CGRectZero; } - (NSArray *)selectionRectsForRange:(UITextRange *)range { return nil; } - (BOOL)canPerformAction:(SEL)action withSender:(id)sender { if (action == @selector(copy:) || action == @selector(selectAll:) || action == @selector(paste:)) { returnNO; } return [super canPerformAction:action withSender:sender]; }

http://b2cloud.com.au/tutorial/disabling-the-caret-and-text-entry-in-uitextfields/


Espero que esto te sea de utilidad.

Poner cursor UIColor -> Vaciar. En la interfaz de usuario, se ocultará.

[[self.textField valueForKey:@"textInputTraits"] setValue:[UIColor clearColor] forKey:@"insertionPointColor"];


Ocultar el cursor es mucho más sencillo en iOS 7. Aún se necesitan algunos trucos para desactivar la lupa

textField.tintColor = [UIColor clearColor];


Para deshabilitar cualquier interacción con el campo de texto, excepto para convertirlo en un primer respondedor, solo puede colocar un UIButton del mismo tamaño sobre el campo de texto. El código para el evento de toque de botón podría ser algo como esto:

- (IBAction)btnEditPhoneTapped:(id)sender { if (self.tfClientPhoneNo.isFirstResponder == NO) [self.tfClientPhoneNo becomeFirstResponder]; }


Para tener un UITextField sin interacción, pero aún trabajar con un inputView :

Subclase UITextField con estos métodos:

// Hide the cursor - (CGRect)caretRectForPosition:(UITextPosition*)position { return CGRectZero; } // All touches inside will be ignored // and intercepted by the superview - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event { return NO; }

El último método evitará por sí solo cualquier edición y la lupa, ya que no podrá tocar el campo de UITextField .

Esto funciona muy bien si está utilizando un campo de texto en un UITableViewCell por ejemplo, y luego puede cambiar el estado del primer tableView:didSelectRowAtIndexPath: través de tableView:didSelectRowAtIndexPath:


Subclase UITextField

//Disables caret - (CGRect)caretRectForPosition:(UITextPosition *)position { return CGRectZero; } //Disables magnifying glass -(void)addGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer { if ([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]]) { gestureRecognizer.enabled = NO; } [super addGestureRecognizer:gestureRecognizer]; }

En tu UITextFieldDelegate

//Prevent text from being copied and pasted or edited with bluetooth keyboard. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { return NO; }

Ahora simplemente configure su texto mediante programación a partir del resultado de su UIPickerView / UIDatePicker.